What is the best way to access specific values in an array in PHP?

To access specific values in an array in PHP, you can use the array index or key associated with the value you want to retrieve. If the array is indexed numerically, you can access values using their numerical index. If the array is associative, you can access values using their corresponding keys.

// Sample array
$array = array("apple", "banana", "cherry");

// Accessing a specific value by index
echo $array[1]; // Outputs "banana"

// Sample associative array
$assocArray = array("fruit1" => "apple", "fruit2" => "banana", "fruit3" => "cherry");

// Accessing a specific value by key
echo $assocArray["fruit2"]; // Outputs "banana"