samedi 23 novembre 2019

How can i access an individual key and value from an array using a foreach loop in PHP?

I am having trouble just accessing one key and value. Right now i can only echo out the whole array but i want to only get one key and value and echo that out.

PHP

$someArray = array('1', '2', '3', '4');

foreach($someArray as $key => $value){
    echo $value[1];
}

so what im trying to do is to get it to echo out just '2' but in the code above it does not echo anything out ive also tried just echo $value but then it echos out 1234.




Aucun commentaire:

Enregistrer un commentaire