g_p_java Posted February 4, 2009 Share Posted February 4, 2009 $all_arrays_in_one = array(); $ar0 = array(); $ar1 = array(); $ar2 = array(); $ar3 = array(); $j = 0; for($j = 0; $j <= 3 ;$j++) { if($j == 0) $all_arrays_in_one[$j] = $ar0; //$ar0 has a string "My" if($j == 1) $all_arrays_in_one[$j] = $ar1; // $ar1 "name" if($j == 2) $all_arrays_in_one[$j] = $ar2; //$ar2 "is" if($j == 3) $all_arrays_in_one[$j] = $ar3; //$ar3 "g_p" } //for var_dump($all_arrays_in_one); //it prints all the the elements //i then do print implode(" ",$all_arrays_in_one); //add a space //Then i would like to output in the page using echo "My name is g_p" The problem is that print implode(" ",$all_arrays_in_one); doesn't print "My name is g_p" What shall i do? Thanks Quote Link to comment Share on other sites More sharing options...
gevans Posted February 4, 2009 Share Posted February 4, 2009 instead of; print implode(" ",$all_arrays_in_one); do; $implodedArray = implode(" ",$all_arrays_in_one); print $implodedArray; Quote Link to comment Share on other sites More sharing options...
trq Posted February 4, 2009 Share Posted February 4, 2009 You never assign the strings 'My' 'name' 'is' 'g_p' to anything. What exactly is the point of your code? Quote Link to comment Share on other sites More sharing options...
g_p_java Posted February 4, 2009 Author Share Posted February 4, 2009 You never assign the strings 'My' 'name' 'is' 'g_p' to anything. What exactly is the point of your code? I would like to take the values of an array and not the keys and implode them. Usually the examples i have seen are : <?php $array = array('lastname', 'email', 'phone'); $comma_separated = implode(",", $array); echo $comma_separated; // lastname,email,phone ?> The difference is that in my code, when i do vardump i get : In my example here i have an array which consists of {key = id, key = ga,key = ajf,key = bbd } array(4) { [0]=> array(2) { [0]=> string(1) "i" [1]=> string(1) "d" } [1]=> array(2) { [0]=> string(1) "g" [1]=> string(1) "a" } [2]=> array(3) { [0]=> string(1) "a" [1]=> string(1) "j" [2]=> string(1) "f" } [3]=> array(3) { [0]=> string(1) "b" [1]=> string(1) "b" [2]=> string(1) "d" } } Also i did that: $implodedArray = implode(" ",$all_arrays_in_one); print $implodedArray; but i get that error : Warning: implode() [function.implode]: Invalid arguments passed in Quote Link to comment Share on other sites More sharing options...
trq Posted February 4, 2009 Share Posted February 4, 2009 What does.... [code=php:0] echo "<pre>'; print_r($all_arrays_in_one); echo "</pre>"; display? Quote Link to comment Share on other sites More sharing options...
g_p_java Posted February 4, 2009 Author Share Posted February 4, 2009 What does.... [code=php:0] echo "<pre>'; print_r($all_arrays_in_one); echo "</pre>"; display? Well i need to display what $all_arrays_in_one outputs: e.g. adjikl , to print a whole string I mean not like this * => string(1) "b" [1]=> string(1) "b" [2]=> string(1) "d" } } etc Quote Link to comment Share on other sites More sharing options...
trq Posted February 4, 2009 Share Posted February 4, 2009 We need to know what $all_arrays_in_one looks like so we can debug / fix your code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.