note 102462 deleted from function.array-push by danbrown

[email protected] Wed, 16 Feb 2011 06:46:33 -0800
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: PortalPress dot org at gmail dot com
Reason: useless

----

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.