How to make array inside in foreach loop – php? [closed]

I suppose you’re looking for this:

$input = array("teamA","teamB","teamC");
$data = [];
foreach($input as $value){
    $assign = "50"; /* The data just temp */
    $data[$value] = $assign;
}

echo $data["teamA"];

If $assign is same for all keys:

$data = array_fill_keys($input, 50);

Browse More Popular Posts

Leave a Comment