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


Groups > comp.lang.php > #11770

Re: array how is done

From Arno Welzel <usenet@arnowelzel.de>
Newsgroups comp.lang.php
Subject Re: array how is done
Date 2013-11-09 08:54 +0100
Message-ID <527DEA2E.7000109@arnowelzel.de> (permalink)
References <1ds2wkcf5vcge$.kr8riwvisibu$.dlg@40tude.net>

Show all headers | 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