Dane Posted January 3, 2008 Share Posted January 3, 2008 Hey guys. Is this possible? I have var's of numbers <?php $inside1 = '4'; $inside2 = '2'; $inside3 = '3'; $inside4 = '4'; $inside1a = '1'; $inside2a = '4'; $inside3a = '2'; $inside4a = '1'; $inside1b = '4'; $inside2b = '1'; $inside3b = '1'; $inside4b = '2'; ?> My question is, how can i output those 3 var's so i get a value such as 1,1,1,1,2,2,2,3,4,4,4,4 Im not talking about just echoing in order... But finding the values of each var and matching it next to its equivalent number.... Ill try and explain more if people need more of an explaination. But that should help. Cheers guys Link to comment https://forums.phpfreaks.com/topic/84249-numbers/ Share on other sites More sharing options...
awpti Posted January 3, 2008 Share Posted January 3, 2008 I guess the first real question is: Why? I'm hoping this is a really bad example of some goal. Link to comment https://forums.phpfreaks.com/topic/84249-numbers/#findComment-429063 Share on other sites More sharing options...
jitesh Posted January 3, 2008 Share Posted January 3, 2008 Can't you take a associative array ? Then its a way to make it easy. Link to comment https://forums.phpfreaks.com/topic/84249-numbers/#findComment-429065 Share on other sites More sharing options...
Dane Posted January 3, 2008 Author Share Posted January 3, 2008 how would i then join up the numbers? Link to comment https://forums.phpfreaks.com/topic/84249-numbers/#findComment-429068 Share on other sites More sharing options...
rajivgonsalves Posted January 3, 2008 Share Posted January 3, 2008 Well as jitesh said have them in a assoc array... it will be easier to work on Link to comment https://forums.phpfreaks.com/topic/84249-numbers/#findComment-429072 Share on other sites More sharing options...
Dane Posted January 3, 2008 Author Share Posted January 3, 2008 Ok, so i created the assoc array. <?php $inside = array( 'top'=>4, 'right'=>2, 'bottom'=>3, 'left'=>4 ); $insidea = array( 'top'=>1, 'right'=>2, 'bottom'=>3, 'left'=>1 ); $insideb = array( 'top'=>4, 'right'=>3, 'bottom'=>4, 'left'=>4 ); $insidec = array( 'top'=>2, 'right'=>3, 'bottom'=>1, 'left'=>1 ); ?> How would i get this to output 1 1 1 1 2 2 2 3 3 3 3 4 4 4 4 4 ? Thanks guys Link to comment https://forums.phpfreaks.com/topic/84249-numbers/#findComment-429223 Share on other sites More sharing options...
jitesh Posted January 3, 2008 Share Posted January 3, 2008 Something like this <?php $associative_array = array(); $associative_array['a0'] = array( 4, 2, 3, 4 ); $associative_array['a1'] = array( 1, 2, 3, 1 ); $associative_array['a2'] = array( 4, 3, 4, 4 ); $associative_array['a3'] = array( 2, 3, 1, 1 ); $new_array = array(); for($i=0;$i<count($associative_array);$i++){ $new_array = array_merge($new_array,$associative_array['a'.$i]); } sort($new_array); for($i=0;$i<count($new_array);$i++){ echo $new_array[$i]." "; } ?> Link to comment https://forums.phpfreaks.com/topic/84249-numbers/#findComment-429230 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.