Search
 
SCRIPT & CODE EXAMPLE
 

PHP

common array methods php

sizeof($arr) //returns the size of elements in the array
is_array($arr) // returns true if $arr is an array and false otherwise
in_array($var, $arr) // check if $var is in the array $arr
print_r($arr) // prints the complete representation of the array
array_merge($arr1, $arr2) //combines $arr1 and $arr2 into a single array
array_values($arr) //store all the values into a new array without the keys but only the values
array_keys($arr) // returns only the keys inside an array
array_pop($arr) // removes the last element of  the array
array_push($arr, $val) // pushes $val to the end of array
array_shift($arr) // removes the first element in the array $arr
sort($arr) // sorts an array in an ascending order

/*Other sorting methods are:
-asort()
-arsort()
-ksort()
-krsort()
-rsort()
*/

array_map('function_name', $arr) // passes each value in the array inside the fuction and do the operation on the array data
array_flip($arr) //This function interchange the keys and the values of a PHP associative array.
array_reverse($arr) //This function is used to reverse the order of elements
array_rand($arr) //randomly pick an element from the array
array_slice($arr, $offset, $length)//This function is used to create a subset of any array





Comment

PREVIOUS NEXT
Code Example
Php :: php display all rows in mysql table 
Php :: current time in laravel migration 
Php :: redirect on validation error laravel to specific section laravel 
Php :: laravel insert 
Php :: base64 decode in php 
Php :: php utf-8 
Php :: php find keyword in string 
Php :: laravel session has message 
Php :: Install ext-dom php 7.2 
Php :: how to check if username already exists in php 
Php :: Wordpress disable plugin or theme installation 
Php :: using a php array in jquery 
Php :: php date + 1 year 
Php :: laravel eloquent get 10 records 
Php :: laravel bindings query 
Php :: install php7.4 linux 
Php :: change php version ubuntu 
Php :: date between query in codeigniter 
Php :: encryption key has not encrypted laravel 
Php :: why css not working with php file 
Php :: db symfony 
Php :: wordpress get post author link 
Php :: decode jwt token laravel 
Php :: increment single column laravel 
Php :: laravel default websie ar 
Php :: php calculate percentage 
Php :: laravel jetstream livewire 
Php :: phpstan exclude line 
Php :: wordpress disable editor 
Php :: yii2 confirm 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =