
Hàm array_unshift() trong PHP - PHP Function
Code $array = array( "php", "js" ); array_unshift($array, "html", "css"); echo "<pre>"; print_r($array); echo "</pre>";

Hàm array_shift() trong PHP - PHP Function
Code $array = array( "php", "js", "html", "css" ); echo array_shift($array); echo "<pre>"; print_r($array); echo "</pre>";

Hàm array_unique() trong PHP - PHP Function
Code $array = array( "a" => "php", "js", "b" => "python", "C#", "php" ); $result = array_unique($array); echo "<pre>"; print_r($result); echo "</pre>";

Hàm array_uintesect() trong PHP - PHP Function
Code $array1 = array( "1" => "html", "2" => "css", "3" => "js", "php" ); $array2 = array( "1" => "python", "z" => "css", "3" => "JS", "C#" ); $result = array_uintersect($array1, $array2, "strcmp"); echo "<pre>"; print_r($result); echo ...

Hàm array_sum() trong PHP - PHP Function
Các phần tử trong mảng đều là số: Code $array = array( 4, 5, 24, 52 ); echo "sum = " . array_sum($array); Kết quả sum = 85

Hàm array_splice() trong PHP - PHP Function
$lenght dương: Code $input = range(0,10); array_splice($input, 5, 4, ["25","22"]); echo "<pre>"; print_r($input); echo "</pre>"; Kết quả Array ( [0] => 0 [1] => 1 [2] => 2 ...

Hàm array_slice() trong PHP - PHP Function
Code $array = range( "a", "f" ); $output = array_slice($array, 2); // returns "c", "d","e","f" $output = array_slice($array, -2, 1); // returns "e" $output = array_slice($array, 0, 3); // returns "a", "b", and "c"

Hàm array_search() trong PHP - PHP Function
Code $array = array( 0 => 'php', 1 => 'js', 2 => 'html', 3 => 'css' ); echo $key = array_search('css', $array)."<br />"; echo $key = array_search('js', $array)."<br />";

Hàm array_reverse() trong PHP - PHP Function
Code $array = array( "php", "js", "css", "html" ); $reversed = array_reverse($array); $preserved = array_reverse($array, true); echo "<pre>"; print_r($array); echo "</pre>"; echo "<pre>"; print_r($reversed); echo "</pre>"; echo ...

Hàm array_replace() trong PHP - PHP Function
Code $array = array( 0=>"php", 1=>"js", 2=>"python", 5=>"html" ); $replacements = array( 0 => "css", 3 => "C#" ); $replacements2 = array( 0 => "java" ); $result = array_replace($array, $replacements, $replacements2); echo "<pre>"; prin ...

Hàm array_replace_recursive() trong PHP - PHP Function
Code $array = array( 'spain' => array( "Madrid") , 'England' => array( "Liverpool", "London" ) ); $replacements = array( 'spain' => array('Barcelona'), 'England' => array('Manchester') ); $result = array_replace_recursive($array, ...

Hàm array_reduce() trong PHP - PHP Function
Cú pháp function sum($result, $item) { $result += $item; return $result; } $array = array( 1, 2, 3, 4, 5 ); //kết quả in ra màn hình sẽ là 15 echo (array_reduce($array, "sum"));

Hàm array_rand() trong PHP - PHP Function
Code $array = array( "php"=>"php", "css"=>"css", "html"=>"html", "python"=>"python", "C"=>"C" ); $rand_keys = array_rand($array, 2); echo "<pre>"; print_r($rand_keys); echo "</pre>";

Hàm array_product() trong PHP - PHP Function
Code $array = array( 1, 2, 8, 5 ); echo "product(array) = " . array_product($array) . "<br />"; echo "product(array()) = " . array_product(array()) . "<br />";

Hàm array_pop() trong PHP - PHP Function
Code $array = array( "css", "html", "php", "js" ); $result = array_pop($array); echo $result; echo "<pre>"; print_r($array); echo "</pre>";

Hàm array_pad() trong PHP - PHP Function
Code $array = array( "css", "html", "php" ); $result = array_pad($array, 5, "js"); echo "<pre>"; print_r($result); echo "</pre>"; $result = array_pad($array, -5, "js"); echo "<pre>"; print_r($result); echo "</pre>"; $result = ...

Hàm array_merge() trong PHP - PHP Function
Code $array1 = array( "php" => "laravel", "css", "html" ); $array2 = array( "python", "php" => "zend", "js" => "nodeJs" ); $result = array_merge($array1, $array2); echo "<pre>"; print_r($result); echo "</pre>";

Hàm array_map() trong PHP - PHP Function
Code function show($name, $age){ echo 'tên của tôi là ' . $name . ', tôi ' . $age . ' tuổi<br />'; } $name = [ 'Minh', 'Peter', 'John' ]; $age = [ 21, 23, 45 ]; array_map('show', $name, $age);

Hàm array_keys() trong PHP - PHP Function
Code $array = array( 0 => "php", "js" => "javascript" ); echo "<pre>"; print_r(array_keys($array)); echo "</pre>"; $array = array( "php", "js", "css", "php", "html", "php" ); echo "<pre>"; print_r(array_keys($array)); echo ...

Hàm array_dift() trong PHP - PHP Function
Code $array1 = array( "php", "js", "css", "python" ); $array2 = array( "php", "js", "javascript", "html" ); $result = array_diff($array1, $array2); echo "<pre>"; print_r($result); echo "</pre>";