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 Link to comment https://forums.phpfreaks.com/topic/143781-question-related-to-arrays-and-print/ 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; Link to comment https://forums.phpfreaks.com/topic/143781-question-related-to-arrays-and-print/#findComment-754365 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? Link to comment https://forums.phpfreaks.com/topic/143781-question-related-to-arrays-and-print/#findComment-754371 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 Link to comment https://forums.phpfreaks.com/topic/143781-question-related-to-arrays-and-print/#findComment-754397 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? Link to comment https://forums.phpfreaks.com/topic/143781-question-related-to-arrays-and-print/#findComment-754401 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 Link to comment https://forums.phpfreaks.com/topic/143781-question-related-to-arrays-and-print/#findComment-754457 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. Link to comment https://forums.phpfreaks.com/topic/143781-question-related-to-arrays-and-print/#findComment-754565 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.