muskokee Posted March 12, 2007 Share Posted March 12, 2007 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 Link to comment https://forums.phpfreaks.com/topic/42296-solved-problems-passing-an-imploded-string-into-a-functions-arguments/ Share on other sites More sharing options...
genericnumber1 Posted March 12, 2007 Share Posted March 12, 2007 what exactly are you trying to do? pass the imploded array in as "$top_name_display" or as all the params of the function? Link to comment https://forums.phpfreaks.com/topic/42296-solved-problems-passing-an-imploded-string-into-a-functions-arguments/#findComment-205185 Share on other sites More sharing options...
muskokee Posted March 12, 2007 Author Share Posted March 12, 2007 All the parameters This is what it looks like when I use the above code 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! Link to comment https://forums.phpfreaks.com/topic/42296-solved-problems-passing-an-imploded-string-into-a-functions-arguments/#findComment-205190 Share on other sites More sharing options...
kenrbnsn Posted March 12, 2007 Share Posted March 12, 2007 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 Link to comment https://forums.phpfreaks.com/topic/42296-solved-problems-passing-an-imploded-string-into-a-functions-arguments/#findComment-205195 Share on other sites More sharing options...
Glyde Posted March 12, 2007 Share Posted March 12, 2007 Since you'll probably have a variable amount of arguments...take a look at: http://us2.php.net/manual/en/function.call-user-func-array.php Also, you'll need to look at: http://us2.php.net/manual/en/function.func-get-args.php Link to comment https://forums.phpfreaks.com/topic/42296-solved-problems-passing-an-imploded-string-into-a-functions-arguments/#findComment-205203 Share on other sites More sharing options...
muskokee Posted March 12, 2007 Author Share Posted March 12, 2007 THANKS TO BOTH OF YOU!!! I'll take both pieces of advice and run with them Link to comment https://forums.phpfreaks.com/topic/42296-solved-problems-passing-an-imploded-string-into-a-functions-arguments/#findComment-205206 Share on other sites More sharing options...
muskokee Posted March 12, 2007 Author Share Posted March 12, 2007 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 Link to comment https://forums.phpfreaks.com/topic/42296-solved-problems-passing-an-imploded-string-into-a-functions-arguments/#findComment-205230 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.