Jump to content

[SOLVED] problems passing an imploded string into a functions arguments


muskokee

Recommended Posts

Hi everyone,

I truly hope someone can assist.  :-*

 

I have a serialized array that I am pulling from mysql and I am attempting to pass the unserialized, imploded string into the arguments of a function.

 

After hours of fiddling...nothing has changed  :'(  The function is completely ignoring the string.

 

I'll show you what I have done:

 

$my_page = unserialize(get_option('webdezine_pages')); //the unserialized array

$my_page = '\'' . implode('\',\'', $my_page).'\''; //the imploded array

 

//the function that I want to pass the string to
function get_menu($block_class) {
global $my_page;
echo '<div class="'.$block_class.'">';
webdezine_list_pages($my_page);
echo '</div>';
}

 

//the start of the function that accepts the arguments
function webdezine_list_pages ($top_name_display='Pages',$head_name_class='top_page', $sub_parent_link_class='mid_page').......

 

If anyone knows why the string is ignored I would love to hear! 

 

Thanks...its great to have a place to talk to other php freaks 8)

All the parameters

This is what it looks like when I use the above code

 

problemmenu.gif

 

It just printing the string.  When I type the same thing in manually it works as expected.  But I need to pull the values from the database!

So you're creating a comma separated string and passing that to your function expecting that each element in the string will pass as a separate argument.  That is an incorrect assumption. It passes as one string.

 

You can try this instead:

<?php
$my_page = unserialize(get_option('webdezine_pages')); //the unserialized array
list ($tnd, $hnc, $spl) = $my_page; 
webdezine_list_pages($tnd, $hnc, $spl);
?>

 

Ken

Thanks again.  I got it fixed thanks to you guys.  Because the array was an associative one I ended up using array_values() first and then using the call_user_func_array() to pass the indexed array to the function.  And so ends a long day in front of the screen ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.