0

I have a function named category_name() which use in a while loop give me a different value everytime I echo it.

I have another function named query_item() which is use in the same loop. I need to get result from first function in the second function.

Can I use call_user_func() and - how / what - do I need to do?
Explenation in PhP manual is complexed.

EXAMPLE
first loop
category_name() is Building1
query_item(Building1) is Room1, Room2

second loop
Second loop category_name() is Building2
Second loop query_item(Building2) is Room4, Room5

So, using the second function, with value of first function, would give me the rooms inside the building.

Please explain to me using the example. I am open to functions alternatives.

2
Contributors
3
Replies
11
Views
4 Years
Discussion Span
Last Post by pritaeas
0

You can just pass it as a parameter, it would look something like this:

function query_item($category) {
    // ...
}

while ( ) {
    $category = category_name();
    $buildings = query_item($category);
}

call_user_func() is designed for callbacks, which I doubt are the solution to your problem.

Edited by pritaeas

0

I thought the function call_user_func() was designed to use a function inside another function?
So how do I use your example in my code?

<?php 
//loop here, followed by this code

   query_item("Building1") ; // should be output of category_name().
   while ( has_Rooms () ) {  // is yes if query_item("Building1") has rooms.
   echo category_name () ;   // outputs Building1, and after first loop Building2, etc. 
   echo Rooms ();            // outputs for example Room1 in Building1 in first loop.
   } 

//end of code, end of loop here.
?>
0

Hard to say from that single code snippet. The logic shown is flawed. Without knowing what those functions are returning, providing a solid guideline is near impossible.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.