Numeric arrays use number as access keys. These arrays can store numbers, strings and any object but their index will be represented by numbers. And array index by default start from zero.
Example-
In this example showing how to create and access numeric indexed array. In this example we have used array() function to create array. And here we have explain array index and array value.
<!DOCTYPE html>
<html>
<head>
<title>Numeric Index Array</title>
</head>
<body>
<?php
#Create array
$num = array('100','200','300','400','500','600','700','800');
#Access array
#Print Index
foreach ($num as $key => $value) {
echo "Array index is is ".$key."<br>";
}
#Print value
foreach ($num as $key => $value) {
echo "Array value is ".$value."<br>";
}
?>
</body>
</html>
|
Example-
In this example showing how to create and access numeric indexed array. Here we have create numeric array as manual. In this example create array without using array() function.
<!DOCTYPE html>
<html>
<head>
<title>numeric index array manual</title>
</head>
<body>
<?php
#Create array
$num['5'] = "Monday";
$num['6'] = "Tuesday";
$num['7'] = "Wednesday";
$num['8'] = "Thursday";
$num['9'] = "Friday";
$num['10'] = "Saturday";
$num['11'] = "Sunday";
#Access array as index
foreach ($num as $key => $value) {
echo "Array index is ".$key."<br>";
}
#Access array as value
foreach ($num as $key => $value) {
echo "Array index is ".$value."<br>";
}
?>
</body>
</html>
|
0 Comments