Jump to content


Check out our Community Blogs

uniqueideaman

Member Since 12 Oct 2016
Offline Last Active Jun 23 2017 04:13 PM
-----

Topics I've Started

Why Associative Array Creation Has "=>" And Numerical Array Not ?

21 May 2017 - 04:25 AM

 
 
Associative Array
 
<html>
   <body>
      
      <?php
         /* First method to associate create array. */
[b]         $salaries = array("mohammad" => 2000, "qadir" => 1000, "zara" => 500);[/b]
         
         echo "Salary of mohammad is ". $salaries['mohammad'] . "<br />";
         echo "Salary of qadir is ".  $salaries['qadir']. "<br />";
         echo "Salary of zara is ".  $salaries['zara']. "<br />";
         
         /* Second method to create array. */
         $salaries['mohammad'] = "high";
         $salaries['qadir'] = "medium";
         $salaries['zara'] = "low";
         
         echo "Salary of mohammad is ". $salaries['mohammad'] . "<br />";
         echo "Salary of qadir is ".  $salaries['qadir']. "<br />";
         echo "Salary of zara is ".  $salaries['zara']. "<br />";
      ?>
   
   </body>
</html>
 
 
Numerical Array
 
 
<?php      
/* First method to create array. */
$numbers = array( one, two, three, four, five);
         
foreach( $numbers as $value ) {
    echo "Value is $value <br />";
    }
         
    /* Second method to create array. */
    $numbers[0] = "one";
    $numbers[1] = "two";
    $numbers[2] = "three";
    $numbers[3] = "four";
    $numbers[4] = "five";
         
foreach( $numbers as $value ) {
    echo "Value is $value <br />";
    }
?>
      
   </body>
</html>
 
 
Look at both code's bold parts on how each different type of arrays create an array.
 
The Associative Array:
/* First method to associate create array. */
         $salaries = array("mohammad" => 2000, "qadir" => 1000, "zara" => 500);
 
 
The Numerical Array:
         /* First method to create array. */
         $numbers = array( 1, 2, 3, 4, 5);
 
Why one uses "=>" and one not ? Are they not both procedural style ?
Look:
 

Numerically Indexed Arrays

20 May 2017 - 03:23 AM

Fellow Php Buds,
 
Do you mind telling me, according to you:
 
1. How many variables are listed below ? And, 
2. How many numerically Indexed Arrays ?
 
$employee_array[0] = "Bob";
$employee_array[1] = "Sally";
$employee_array[2] = "Charlie";
$employee_array[3] = "Clare";
 
 
Thank You

How Come Variable Not Assigned And Php Knows Where To Look For Value ?

06 May 2017 - 04:21 AM

Good Weekend Folks!
 
 
I have a question.
I do not understand how php knows how to define this variable $value in the following example since it has not been declared. How does it know what that variable represents since no  reference or pointer has been assigned to it ? Strange!
 
 
 
<html>
   <body>
   
      <?php
         /* First method to create array. */
         $numbers = array( 1, 2, 3, 4, 5);
         
         foreach( $numbers as $value ) {
            echo "Value is $value <br />";
         }
         
         /* Second method to create array. */
         $numbers[0] = "one";
         $numbers[1] = "two";
         $numbers[2] = "three";
         $numbers[3] = "four";
         $numbers[4] = "five";
         
         foreach( $numbers as $value ) {
            echo "Value is $value <br />";
         }
      ?>
      
   </body>
</html>
 
 
I thought "array_values()" was supposed to be there in the above example but "$value" is there instead.
What is the difference between the 2 ?
 
The following seems to be in pdo, which I haven't started learning just yet: