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.

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.

Recommended Answers

All 3 Replies

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.

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?

//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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.