Code:
if ( $_GET['tab'] == 'newest' ) {
// Go through each question
foreach( array_reverse( $end_array, true ) as $tags_and_Qid['question_id'] => $titles_and_Qid['title'] )
{
// Grab the title for the first array
$title = $titles [ $tags_and_Qid['question_id'] ] ['title'];
// Grab the tags for the question from the second array
$tags = $end_array [ $tags_and_Qid['question_id'] ] ['tag'];
// Grab the username for the question from the second array
$username = $usernames [ $tags_and_Qid['question_id'] ] ['username'];
--- cut ----
}
}
I need to use this code often. The only difference is the array_reverse (..., true)
in the first example.
I have tried to solve the problem by making a function organize_question
to solve this problem. I was unsuccessful:
function organize_questions ( $tab ) {
if ( $_GET['tab'] == 'newest' ) {
echo ( "array_reverse ( $end_array , true )" );
// Problem here!
}
if ( $_GET['tab'] == 'oldest' ) {
echo ( "$end_array" );
// this does not work
} else {
echo ( "array_reverse ( $end_array , true )" );
// Problem here!
}
}
I then changed the relevant line in my code to this:
foreach( organize_question( $tab ) as $tags_and_Qid['question_id'] => $titles_and_Qid['title'] )
The problem is in transferring variables from one function to another.
I tried to put all necessary variables in the parameters of the function, but everything gets broken, since there are many dependencies on this function.
I am new to PHP so there must be easier way to do this than what I am trying.