$data = [ 'name' => 'John', 'age' => 25, 'address' => [ 'street' => '123 Main St', 'city' => 'New York', 'state' => 'NY', 'zip' => '10001' ] ]; // get the value of key 'name' $name = JArrayHelper::getValue($data, 'name'); echo $name; // John // get the value of nested array key 'city' $city = JArrayHelper::getValue($data, 'address.city'); echo $city; // New York
$fruits = [ 'apple' => [ 'color' => 'red', 'taste' => 'sweet', 'price' => 1.99 ], 'orange' => [ 'color' => 'orange', 'taste' => 'sour', 'price' => 2.49 ] ]; // get the price of apple $applePrice = JArrayHelper::getValue($fruits, 'apple.price'); echo $applePrice; // 1.99 // get the taste of orange $orangeTaste = JArrayHelper::getValue($fruits, 'orange.taste'); echo $orangeTaste; // sourIn this example, we have an array of fruits with nested arrays containing their attributes. The getValue function is used to retrieve the price of 'apple' and the taste of 'orange'. Package library: Joomla Framework