php get array value code example

Example 1: array values php

<?php
  
$array = array("size" => "XL", "color" => "gold");

print_r(array_values($array));

?>

Example 2: php get all values from array

array_values(array)

Example 3: php array_values

<?php
$array = array("size" => "XL", "color" => "gold");
print_r(array_values($array));
?>
// ["XL","gold"]

Example 4: php return array

<?php

function data() {
    $out[0] = "abc";
    $out[1] = "def";
    $out[2] = "ghi";
    return $out;
}

$data = data();
foreach($data as $items){
    echo $items;
}

Example 5: php variables as keys in arrays

$id = 1;
$age = 2;    
$sort = "id"; // or "age";
    $Key = $$sort;
$arr = array($Key => 'string');

print_r($arr);

Tags:

Php Example