[Solved] php foreach array id value


You didn’t provided proper source code of your array. So
I couldn’t understand properly I think, still I’m trying to answer.

If your ID number and text both are stored in $list array values, like this –

$list = array(
‘id1:text 1’,
‘id2:text 2’,

);

then you could do something like this

$idArr= array();

foreach ($list as $li) {
    $id = explode(":", $li)[0]; //first value before : sign
    //$id = trim($id); //to remove spaces if any (optional)
    array_push($idArr, $id);
}


print_r($idArr); //all your ids

If your array is like this

$list = array(
id1 => ‘text 1’,
id2 => ‘text 2’,

);

Then you can do like this

$idArr = array_keys($list);

print_r($idArr); // your ids

0

solved php foreach array id value