I am new to multidimensional array in php, I read this SO answer and I tried to create my bidimensional array but how do I output it?
$nPost = array("orange, table");
$count_values = array("fruit, forniture");
$final_array = array(array($count_values), array($nPost));
Output would have to be:
Fruits: orange, Forniture: table
Tried
print_r($final_array)
;
But i got
Array ( [0] => Array ( [0] => Array ( [0] => fruit, forniture ) ) [1] => Array ( [0] => Array ( [0] => orange, table ) ) )
0 fruit, forniture
UPDATE
Real life full code is (explanation in code comments):
<?php
$stack = array();
$userID = array();
$nPost = array();
$blogusers = get_users( 'orderby=nicename&role=author' );
foreach ( $blogusers as $user ) {
// get the language list for each user, and push to array
$descTokens = explode(',', $user->user_description);
$stack = array_merge($stack, $descTokens);
// get the ID for each user, and push to the array
// get the number of posts for each user ID and push to array
$the_user_id = $user->ID;
$numPosts = count_user_posts( $the_user_id );
array_push($userID, $the_user_id);
array_push($nPost, $numPosts);
}
// get the count for each language by counting the duplicate strings
$count_values = array();
foreach ($stack as $a) {
@$count_values[$a]++;
}
$total_duplicates = 0;
foreach ($count_values as $a) {
if($count_values[$a]<=1){
unset($count_values[$a]);
} else{
$total_duplicates += $count_values[$a];
}
}
for($i = 0; $i < count($count_values); $i++){
$final_array[$count_values[$i]] = $nPost[$i];
}
foreach($final_array as $label => $item){
echo "$label: $item, ";
}
?>
// This gives me a correct result but not the n. posts
<ul>
<?php
foreach ($count_values as $key=>$count) {
echo '<li>'.$key.' '.$count.'</li>';
}
?>
</ul>
What we're trying to achieve is:
- 1 French with 2 posts
- 3 English with 5 posts