Php Interview Questions 2015

  1. What is the difference between a numeric and an associative array?
    =>
    A numeric array can be indexed numerically using numbers or numeric variables.
    An associative array uses alphanumeric identifiers to index elements.
 Example of Numeric Array :
Adding items to an array
<?php
$names[] = “Sachin”;
$names[] = “Sehwag”;
$names[] = “Rahul”;
$names[] = “Laxman”;
print_r($names);
?>

Example of Associative Array :
Adding items to an array using explicit locations
<?php
$names[0] = “Sachin”;
$names[1] = “Sehwag”;
$names[2] = “Rahul”;
$names[3] = “Laxman”;
print_r($names);
?>
Output of both the programs is same as :
Array
(
[0] => Sachin
[1] => Sehwag
[2] => Rahul
[3] => Laxman
)

No comments: