ridiculous Posted May 19, 2007 Share Posted May 19, 2007 Hello. I have an array called $value which, when echoed, returns [12345]. Instead, I desire to reformat this array so that it prints or echoes in the following format: ["1","2","3","4","5"]. So far, I have: echo """ , $value , "", "; ////["1","2","3","4","5"]. This yields my desired result, but I want to encapsulate that result in a variable. I have tried $k = echo """ , $value , "", "; with no success. My objective is to have echo $k; ///return "1","2","3","4","5" Any guidance is much appreciated. Link to comment https://forums.phpfreaks.com/topic/52160-reformatting-an-array-and-printing-the-result/ Share on other sites More sharing options...
kenrbnsn Posted May 19, 2007 Share Posted May 19, 2007 Try this: <?php $str = '12345'; $tmp = array(); for ($i = 0;$i<strlen($str);$i++) $tmp[] = $i; $var = implode(',',$tmp); echo $var; ?> Ken Link to comment https://forums.phpfreaks.com/topic/52160-reformatting-an-array-and-printing-the-result/#findComment-257264 Share on other sites More sharing options...
ridiculous Posted May 20, 2007 Author Share Posted May 20, 2007 Thanks! Actually, I ended up getting what I wanted by doing this: $k = "" $value ","; print $k; That returns each of the values from my array formatted as desired. However, now I am trying to inject this variable into an array like so: $chart[ 'chart_data' ] = array ( array ( "","1","2","3","4","5", ), array (print $k) ); I guess I can't just write "print $k" as a value for the array. Any ideas on how to have php parse array ($k) like it would array ("",1,2,3,4,5) Thanks for the feedback. Link to comment https://forums.phpfreaks.com/topic/52160-reformatting-an-array-and-printing-the-result/#findComment-257270 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.