This is my array:
$wp_session = array(
'id' => $id,
'id2' => $id2,
'p1' => $p1,
'p2' => $p2
);
The result was giving me a Recursive_ArrayAccess so I searched on how to fix it and came across these answers:
PHP - Recursive Multidimension Array iterator PHP foreach() with arrays within arrays?
So I added/changed my foreach statement to:
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($wp_session);
//Split the parameters with &
foreach ($iterator as $key => $value) {
if(!empty($value)){
$fields .= $key . '=' . $value . '&';
}
//Remove the last &
$fields2 = substr($fields, 0, -1);
}
But then the page breaks.
I also tried:
$iterator = array_walk_recursive($wp_session);
The page doesn't break but $fields2 is not outputting the data in the next foreach statement. This is the whole code:
//Start a session
$wp_session = WP_Session::get_instance();
//Get the current parameters
$id = $_GET['id'];
$id2 = $_GET['id2'];
$p1 = $_GET['p1'];
$p2 = $_GET['p2'];
$wp_session = array(
'id' => $id,
'id2' => $id2,
'p1' => $p1,
'p2' => $p2
);
//array_walk_recursive($wp_session);
//$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($wp_session);
$iterator = array_walk_recursive($wp_session);
//Split the parameters with &
foreach ($iterator as $key => $value) {
if(!empty($value)){
$fields .= $key . '=' . $value . '&';
}
//Remove the last &
$fields2 = substr($fields, 0, -1);
}
if( is_admin() )
return $items;
//Get the menu items and add the above parameters to the menu items urls
foreach( $items as $item )
{
if($wp_session){
$item->url .= '?' . $fields2;
}
}
return $items;
Can someone please explain what I am doing wrong? Any kind of help or suggestions will be appreciated!
)forRecursiveIteratorIterator