Jump to content

help with Multidimensional arrays


spires

Recommended Posts

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

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'];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.