P粉3109311982023-08-07 11:24:14
$user = array( 'name' => 'John', 'age' => 35 ); // echo key($user)." is ".($user[key($user)]).","; $counter = count($user); $i = 1; $res = ''; foreach ($user as $key => $value) { $res .= $key. " is ". $value; if ($counter != $i) { $res = $res .", "; } $i = $i + 1; } echo $res;