Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <3677958.dk8vouHeg2@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Fri, 15 Nov 2013 15:11:48 +0100 User-Agent: KNode/4.10.5 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. MIME-Version: 1.0 Lines: 45 NNTP-Posting-Date: 15 Nov 2013 15:12:14 CET NNTP-Posting-Host: c39cc495.newsspool1.arcor-online.net X-Trace: DXC=_8;Rhm63N\XAX0F2i> 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