FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » array how is done
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: array how is done [message #183679 is a reply to message #183678] Sat, 09 November 2013 07:54 Go to previous messageGo to previous message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma:
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
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: $dom->loadHTMLFile() error
Next Topic: IT company looking for skilled resources
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 01 06:24:05 GMT 2024

Total time taken to generate the page: 0.04199 seconds