settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: I want to use while with array (Php)

+6 votes

I want to use while with array - have 3 arrays (maybe some products) with Php. Thanks

asked in PHP category by user mitko

1 Answer

+5 votes

Try this code:

<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>While and Array in Php</title>
</head>
<body>

<?php

$goods = [
	[
		'title'       => 'Nokia',
		'price'       => '$100',
		'description' => 'Info'
	],
	[
		'title'       => 'Surface Pro 6',
		'price'       => '£600',
		'description' => 'Info'
	],
	[
		'title'       => 'Sony',
		'price'       => '£300',
		'description' => 'Info'
	]
];

$i = 0;
while ( $i < 3 ) {
	echo $goods[ $i ]['title'] . ' - ' . $goods[ $i ]['price'];
	echo '<br>';
	$i++;
}

?>

</body>
</html>

 

answered by user matthew44
...