Skip to content
Advertisement

how to convert this block of code into a php version

JavaScript

// Javascript program to check if all array elements are // same or not.

JavaScript

// This code is contributed by patel2127

Advertisement

Answer

Taking the information from the question previously dealt with here:

Check if all values in array are the same

I think your function would look like this:

JavaScript

array_unique() returns the same array with all duplicates removed and count() counts the number of elements in an array.

If the array $arr only has one value after all duplicates are removed then all the values in the original array are unique.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement