Hosted by Dailymotion. For legal issues report at the Copyright Center, report us on DMC, or use the Instant Removal tool.
PHP MYSQL LESSON 6 ( PART 2 ) _ ARRAY IN PHP
1 Views • Dec 16, 2017
Description
Floats are also cast to integers, which means that the fractional part will be truncated. E.g. the key 8.7 will actually be stored under 8.
Bools are cast to integers, too, i.e. the key true will actually be stored under 1 and the key false under 0.
Null will be cast to the empty string, i.e. the key null will actually be stored under "".
Arrays and objects can not be used as keys. Doing so will result in a warning: Illegal offset type.
If multiple elements in the array declaration use the same key, only the last one will be used as all others are overwritten.
Example #2 Type Casting and Overwriting example
"a",
"1" => "b",
1.5 => "c",
true => "d",
);
var_dump($array);
?>
The above example will output:
array(1) {
[1]=>
string(1) "d"
}
As all the keys in the above example are cast to 1, the value will be overwritten on every new element and the last assigned value "d" is the only one left over.
PHP arrays can contain integer and string keys at the same time as PHP does not distinguish between indexed and associative arrays.
Example #3 Mixed integer and string keys
"bar",
"bar" => "foo",
100 => -100,
-100 => 100,
);
var_dump($array);
?>
The above example will output:
array(4) {
["foo"]=>
string(3) "bar"
["bar"]=>
string(3) "foo"
[100]=>
int(-100)
[-100]=>
int(100)
}
The key is optional. If it is not specified, PHP will use the increment of the largest previously used integer key.
More from User
Almond Butter Recipe
Akash Jangra
PHP MYSQL LESSON 7 ( PART 1 ) _ LOOPS IN PHP
Akash Jangra
PHP MYSQL LESSON 6 ( PART 2 ) _ ARRAY IN PHP
Akash Jangra
PHP MYSQL LESSON 6 ( PART 1 ) _ ARRAY IN PHP
Akash Jangra
PHP MYSQL LESSON 5 (Part 1) _ OPERATORS IN PHP
Akash Jangra
PHP MYSQL LESSON 5 ( Part 2 ) _ OPERATORS IN PHP
Akash Jangra
Related Videos
Read PHP MySQL Web Programming Interview Questions Answers and Explanations: PHP MySQL FAQ
Boesen
Just Enough Web Programming with XHTML PHP and MySQL
Jamesgoff
Web Development with PHP &MySQL Tutorial-7-Associative Array in PHP
WEB Development Trainer
Dynamic Web Design with PHP and MySQL Training Video What Is PHP
Social Frontier
Read Web Programming for Business: PHP Object-Oriented Programming with Oracle Ebook Free
Rmetz
Web Development with PHP &MySQL Tutorial-5-Index Arrays
WEB Development Trainer