array how is done

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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

nawfer, 2013-11-09 07:53:

Quoted text here. Click to load it

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:

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(

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


Arno Welzel

Re: array how is done

nawfer wrote:

Quoted text here. Click to load it


Sometimes, what you learn is wrong. If those wrong ideas are close to the  
root of the knowledge tree you build on a particular subject, pruning the  
bad branches can sometimes cause the whole tree to collapse.

Site Timeline