Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #11770

Re: array how is done

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Arno Welzel <usenet@arnowelzel.de>
Newsgroups comp.lang.php
Subject Re: array how is done
Date Sat, 09 Nov 2013 08:54:22 +0100
Lines 49
Message-ID <527DEA2E.7000109@arnowelzel.de> (permalink)
References <1ds2wkcf5vcge$.kr8riwvisibu$.dlg@40tude.net>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Trace individual.net OWBzL+8pxDM7+wAhrvdD/ALh5Nw+Qb4koT7rPouLXkicK09uGt
Cancel-Lock sha1:rrtgIvZ0ygwvyMsGFBVPledWjzI=
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0
In-Reply-To <1ds2wkcf5vcge$.kr8riwvisibu$.dlg@40tude.net>
X-Enigmail-Version 1.6
Xref csiph.com comp.lang.php:11770

Show key headers only | View raw


nawfer, 2013-11-09 07:53:

> if I have this code
> 
> foreach($models as $md)
> {$articles[] = array($md->id,$md->name);}
> 
> with an example (really value) can explain how can to be the $models and  
> how is $articles[]

I'm not sure if I understand what you want to know.

Well - $models may be an array of objects and $articles will be an array
of values:

<?php
class Model
{
  public $id;
  public $name;
}

$model1 = new Model();
$model1->id = 1;
$model1->name = "dog";

$model2 = new Model();
$model2->id = 2;
$model2->name = "cat";

$models = array(
  $model1,
  $model2
);

foreach($models as $md)
{
  $articles[] = array($md->id, $md->name);
}

var_dump($models);
var_dump($articles);
?>


-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

array how is done nawfer <novalidsforspam@alt.al> - 2013-11-09 07:53 +0100
  Re: array how is done Arno Welzel <usenet@arnowelzel.de> - 2013-11-09 08:54 +0100
  Re: array how is done Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-09 14:59 +0100

csiph-web