FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Declaring an array necessary?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Declaring an array necessary? [message #184974 is a reply to message #184969] Fri, 21 February 2014 21:58 Go to previous messageGo to previous message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma:
Senior Member
Am 21.02.2014 18:56, schrieb The Natural Philosopher:
> I was just wondering. Php assumes a varibale exists as soon as it is assigned a
> value, but a function exists to create an array..

I would rather say: PHP creates a variable as soon as you assign a value to one that
does not exist.

> Sop can one just say
>
> $arr['hello']='sexy';
>
> or should there be
>
> $arr=array();
>
> first?
>

I would do a
$arr = array()
before I start to store data from the database into it, because a query could give
zero records, and I don't want my script killed on the next foreach.

There is redundancy in many programming languages, in the sense that you can get the
same result with several different expressions. So I would not worry too much about
why array() exists.


/Str.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: strpos() before str_replace()? Or, maybe strtr()?
Next Topic: Career Opportunities in Singapore (PHP Tech Lead)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 11:12:07 GMT 2024

Total time taken to generate the page: 0.04786 seconds