note 102462 added to function.array-push
[email protected] Wed, 16 Feb 2011 06:23:50 -0800
| Newsgroups | php.notes |
|---|---|
| Message-ID | <[email protected]> |
I read much here, but why do people as Ariz Jacinto 27-Jun-2008 11:41 offer "solutions" that simply throws errors? I read their "coding" and I just know, it will never work! Do they ever test their own "coding"? It happens so very often, I decided to become a poster at PHP.net. And no ... I will NOT be mild. Let those "master-coders" go back to school. I'm sorry ... I have no other words for the "solutions" some post and I do not want to be offensive, but "Intelligent Design" is no science.
You can NOT use Ariz Jacinto's "solution" to push a key as I will show you.
Throws AN error [Ariz Jacinto's solution] :
if(is_array($some_array)) {
/* so, this IS an ARRAY */
array-push($some_array[$a_key],$any_value);
}
Error : array_push() [function.array-push]: First argument should be an array ... why? Because $some_array[$a_key] is a VALUE (element) and NOT an ARRAY!
Throws NO error AND works [PortalPress.org solution] :
if(is_array($some_array)) {
/* so, this IS an ARRAY */
$some_array[count($some_array)]=$any_value;
/* we added a new element with the last number as key */
$all_keys=array_keys($some_array);
$all_values = array_values($some_array);
$all_keys[(count($some_array)-1)]=$a_key;
$some_array=array_combine($all_keys,$all_values);
}
Simple, nay? But then again, I've been around since Basic and by now, tell programmers what to do, instead of programming myself. Can you imagine, what I do with "Wizz-Kids" and their preg_match "solutions"? "Go and write that in regular coding and then come back". That mobile-phone generation don't even know, what regular coding is; they'd rather waste useless processor capacity then write the best coding.
Regards, Igor
P.S.PortalPress.org is still in development [16-02-2011], so don't go Googling on that name for now. Be patient.
----
Server IP: 69.147.83.197
Probable Submitter: 109.34.210.20
----
Manual Page -- http://www.php.net/manual/en/function.array-push.php
Edit -- https://master.php.net/note/edit/102462
Del: integrated -- https://master.php.net/note/delete/102462/integrated
Del: useless -- https://master.php.net/note/delete/102462/useless
Del: bad code -- https://master.php.net/note/delete/102462/bad+code
Del: spam -- https://master.php.net/note/delete/102462/spam
Del: non-english -- https://master.php.net/note/delete/102462/non-english
Del: in docs -- https://master.php.net/note/delete/102462/in+docs
Del: other reasons-- https://master.php.net/note/delete/102462
Reject -- https://master.php.net/note/reject/102462
Search -- https://master.php.net/manage/user-notes.php