How to common array methods php (PHP Scripting Language)

Asked by: Ardwight Bornedal
Edit Question Icon
Edit
Follow Icon
Report Icon
Report

Explain Below What Do You Want to report!


Available Answers: 4

Globez jdpnkr Shreya (STUFFER Investigation) From: Delhi/India
1
<?php
2
$array = array(foobarhelloworld);
3
var_dump($array);
4
?>
Upvote Icon10
Comment IconComment
Follow Icon
Report IconReport

Explain Below What Do You Want to report!


Explain Below What Do You Want to comment!


Kapil Modhwadiya (TOOL GRINDER II Troubleshooting, Outreach, Marketing Strategy) From: Cardiff/Wales
1
sizeof($arr) //returns the size of elements in the array
2
is_array($arr) // returns true if $arr is an array and false otherwise
3
in_array($var, $arr) // check if $var is in the array $arr
4
print_r($arr) // prints the complete representation of the array
5
array_merge($arr1, $arr2) //combines $arr1 and $arr2 into a single array
6
array_values($arr) //store all the values into a new array without the keys but only the values
7
array_keys($arr) // returns only the keys inside an array
8
array_pop($arr) // removes the last element of  the array
9
array_push($arr, $val) // pushes $val to the end of array
10
array_shift($arr) // removes the first element in the array $arr
11
sort($arr) // sorts an array in an ascending order
12
/*Other sorting methods are:
13
-asort()
14
-arsort()
15
-ksort()
16
-krsort()
17
-rsort()
18
*/
19
array_map('function_name', $arr) // passes each value in the array inside the fuction and do the operation on the array data
20
array_flip($arr) //This function interchange the keys and the values of a PHP associative array.
21
array_reverse($arr) //This function is used to reverse the order of elements
22
array_rand($arr) //randomly pick an element from the array
23
array_slice($arr, $offset, $length)//This function is used to create a subset of any array
Upvote Icon8
Comment IconComment
Follow Icon
Report IconReport

Explain Below What Do You Want to report!


Explain Below What Do You Want to comment!


Raj wvvk (YARD WORKER Immigration, Media Relations) From: Phoenix/United States
1
$key_of_max_value = array_search(max($arrCompare),$arrCompare);
Upvote Icon2
Comment IconComment
Follow Icon
Report IconReport

Explain Below What Do You Want to report!


Explain Below What Do You Want to comment!


Prosenjit Narayana (FLATWORK FINISHER Public Policy, Product Management, Mis, Product Knowledge) From: Thrissur/India
1
if (count($arr) > 1) {
2
     ....
3
}
Upvote Icon1
Comment IconComment
Follow Icon
Report IconReport

Explain Below What Do You Want to report!


Explain Below What Do You Want to comment!




More Questions


Would you like to join Ask Sawal!

Why?

  1. Ask Sawal is a fast growing question and answer discussion forum.

  2. 15 lakh+ questions were answered by our Ask Sawal Members.

  3. Each day 1000s of questions asked & 1000s of questions answered.

  4. Ask any question and get answer from 2.5 Lakh+ Ask Sawal Members.

  5. Constant moderation and reporting option makes questions and answers spam free.

  6. And also, we have free blogging platform. Write an article on any topic.

  7. We have 10000+ visitors each day. So a beneficial platform for link building.

  8. We are allowing link sharing. Create backlinks to your blog site or any site.

  9. Gain extra passive income by sharing your affiliate links in articles and answers.