spires Posted June 12, 2011 Share Posted June 12, 2011 Hi. I'm guessing this should be easy, but having never used them i'm stuck. I have an array and count that i'm trying to place inside of a Multidimensional array. $value = count from 1-infinite $keywords = an Array contain X amount of stings. What I want to do, (on submit) is join the two together in to one array. So the lists of "$keywords" can be referenced by a $value. E.G: value1 => keyword1 value1 => keyword2 value1 => keyword3 value2 => keyword1 value2 => keyword2 value2 => keyword3 etc So, I'm thinking something like this, but i'm purely guessing here: $value = 1; $keywords = array("key1", "key2", "key3"); $arr = array($value => array($keywords)); //then loop through foreach($arr as $val){ foreach($val as $keywords){ echo $val. " - " .$keywords."\n"; } } //output 1 - key1 1 - key2 1 - key3 Any ideas where I'm going wrong, or how this should look? Thanks Link to comment https://forums.phpfreaks.com/topic/239160-help-with-multidimensional-arrays/ Share on other sites More sharing options...
xyph Posted June 12, 2011 Share Posted June 12, 2011 <?php $max = 50; $values = array('one','two','three'); $array = array(); for( $i=0; $i<$max; $i++ ) $array[] = $values; print_r( $array ); ?> Link to comment https://forums.phpfreaks.com/topic/239160-help-with-multidimensional-arrays/#findComment-1228767 Share on other sites More sharing options...
spires Posted June 12, 2011 Author Share Posted June 12, 2011 Hi, Thanks. That all look good, but how does the value also get in there? E.G $array[1]['key1']; $array[1]['key2']; $array[2]['key1']; $array[2]['key2']; Thanks Link to comment https://forums.phpfreaks.com/topic/239160-help-with-multidimensional-arrays/#findComment-1228774 Share on other sites More sharing options...
spires Posted June 12, 2011 Author Share Posted June 12, 2011 Any other ides? Link to comment https://forums.phpfreaks.com/topic/239160-help-with-multidimensional-arrays/#findComment-1228782 Share on other sites More sharing options...
xyph Posted June 12, 2011 Share Posted June 12, 2011 Just use this instead $values = array( 'key1' => 'one', 'key2' => 'two', 'key3' => 'three' ); Link to comment https://forums.phpfreaks.com/topic/239160-help-with-multidimensional-arrays/#findComment-1228783 Share on other sites More sharing options...
spires Posted June 12, 2011 Author Share Posted June 12, 2011 ok thanks. But can't get that to work. I'm now trying: $adgroup = $_POST['adgroup']; // This is an array, 100's of keywords $arrValues = array(); for($v=0;$v<$value;$v++){ $arrValues[] = $v; foreach($adgroup as $adgroups){ $cleanGroup = trim($adgroups); $arrValues[$v] = $cleanGroup; } } print_r($arrValues); This works great. But, I can't keep adding to the array. E.G: $v = 1 $arrValues[$v] = $cleanGroup; So, what I want is: $arrValues[1]['key1']; $arrValues[1]['key2']; $arrValues[1]['key3']; Link to comment https://forums.phpfreaks.com/topic/239160-help-with-multidimensional-arrays/#findComment-1228788 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.