array how is done [message #183678] |
Sat, 09 November 2013 06:53 |
nawfer
Messages: 34 Registered: August 2011
Karma: 0
|
Member |
|
|
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[]
|
|
|
Re: array how is done [message #183679 is a reply to message #183678] |
Sat, 09 November 2013 07:54 |
Arno Welzel
Messages: 317 Registered: October 2011
Karma: 0
|
Senior Member |
|
|
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
|
|
|
|