Continuation of Array at PHP part 1....
Access Array Values
1. Index Numeric
There are 2 ways to access array value with index numeric, they are:
a) Direct access, we can directly access array by writing directly array name and index as example below.
Click show to see and copy this code
Below is output.
b) With Looping, the way is there is function additional, it is count() as replacement element index. Let's see example below.
Click show to see and copy this code
Below is output.
2. Index Associative
There are 2 ways to access array value with index associative, they are:
a) Direct access, we can directly access array by writing directly array name and index as example below.
Click show to see and copy this code
Below is output
b) With Looping, because index which is use is not numeric so looping use for is can not be used. We must use foreach loop. Let's see example below.
Click show to see and copy this code
Below is output.
To display the value using a foreach loop, first $brand_motor array is converted into a temporary variable $tmp, which refers to array elements are accessed at the time.And then $key variable refers
the index associative array element are accessed.
Thanks for visiting and reading my article. I hoop this article can be hlep you...
Learn and learn again...
No comments:
Post a Comment