Okay, I'm a newbie. Apologies over to everyone who finds arrays easy...
I want to count all the values of an array. I'm using the function array_count_values.
So good so far, but I want to concatenate a variable, so I need a foreach loop.
I need the following:
$data = apple, bannana, pear
$label = 2, 1, 1
somewhere my logic has gone to pot.
Can anyone put me on the right track?
I want to count all the values of an array. I'm using the function array_count_values.
Code:
$a = array('apple', 'bannana', 'pear', 'apple');
print_r(array_count_values($a));
// Gives Array ( [apple] => 2 [bannana] => 1 [pear] => 1 )
So good so far, but I want to concatenate a variable, so I need a foreach loop.
Code:
$a = array('apple', 'bannana', 'pear', 'apple');
foreach (array_count_values($a) as $value) {
$data .= $value . "*";
$label .= $a[$value] . "*";
}
// $data gives me 211
// $label gives me pearbannanabannana
I need the following:
$data = apple, bannana, pear
$label = 2, 1, 1
somewhere my logic has gone to pot.
Can anyone put me on the right track?