Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

QUESTION 7 Look up the function array_count_values on php.net What is the conten

ID: 3842627 • Letter: Q

Question

QUESTION 7

Look up the function array_count_values on php.net

What is the contents of $newArray after the following code executes?

<?php

$firstArray = array('a','b','c','a','b',65,65);

$newArray = array_count_values($firstArray);

?>

[2] => a [2] => b [1] => c [2] => 65

[a] => 2 [b] => 2 [c] => 1 [65] => 2

[0] => 2 [1] => 2 [2] => 1 [3] => 2

2

[2] => a [2] => b [1] => c [2] => 65

[a] => 2 [b] => 2 [c] => 1 [65] => 2

[0] => 2 [1] => 2 [2] => 1 [3] => 2

2

Explanation / Answer

The answer is:

[a] => 2 [b] => 2 [c] => 1 [65] =>2

array_count_values() returns an array using the values of array as keys and their frequency in array as values.

for example:

<?php
$array = array(1, "welcome", 1, "please", "hello");
print_r(array_count_values($array));
?>

So the Array returned will be:
Array
(
   [1] => 2
   [welcome] => 1
   [please] => 1
   [hello] => 1
)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote