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

Home » Imported messages » comp.lang.php » how change an array
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: how change an array [message #183703 is a reply to message #183702] Fri, 15 November 2013 14:11 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
Senior Member
Norman Peelman wrote:

> On 11/15/2013 07:23 AM, nawfer wrote:
>> with this
>> 1)
>> foreach($models as $md)
>> {$articles[] = array($md->id,$md->name);}
>>
>> I have
>> Array ([0] => Array ([0] => 4 [1] => Libri )
>> [1] => Array ( [0] => 2 [1] => Riviste )
>> [2] => Array ( [0] => 1 [1] => Giornali ) )
>>
>>
>> how can change code 1) for have this:
>>
>> Array ( [4] => Libri
>> [2] => Riviste
>> [1] => Giornali )
>>
>
> foreach($models as $md)
> {
> $articles[$md->id] = $md->name;
> }
>
> or (if above doesn't work)
> foreach($models as $md)
> {
> $tmp = $md->id;
> $articles[$tmp] = $md->name;
> }

Under which circumstances would the second code work, but not the first one?

BTW: You should be writing “foreach (” (and “if (”, “switch (” etc.) so that
it is not mistaken by the reader for a function call.


PointedEars
--
> If you get a bunch of authors […] that state the same "best practices"
> in any programming language, then you can bet who is wrong or right...
Not with javascript. Nonsense propagates like wildfire in this field.
-- Richard Cornford, comp.lang.javascript, 2011-11-14
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: IT company looking for skilled resources
Next Topic: detecting refresh versus initial page load.
Goto Forum:
  

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

Current Time: Mon Nov 04 19:19:06 GMT 2024

Total time taken to generate the page: 0.05085 seconds