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

Home » Imported messages » comp.lang.php » Problem: Read array of array into flat array
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Problem: Read array of array into flat array [message #170868] Sat, 04 December 2010 11:27 Go to next message
gina is currently offline  gina
Messages: 2
Registered: December 2010
Karma: 0
Junior Member
Hey there.

I am having a problem with that array and I don't seem to get my head round
so thought I better ask for some good help ;)


....
foreach ($detailsArray as $details) {
$counter++;
foreach ($details as $key => $value) {

$arrayData[] = array(
'id'.$counter => $value->getId(),
'detail'.$counter => $value->getDetailText()
);
}



rather than an array of array I'd like to have an array containing the
values all in a flat form

the function should return an array like:

$resultArray = array('id1' =>'1', detail1 => 'ABC', id2 =>'1', detail2 =>
'DEF');


How am I going to achieve this ?

TIA gin
Re: Problem: Read array of array into flat array [message #170871 is a reply to message #170868] Sat, 04 December 2010 12:17 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(gina)

> I am having a problem with that array and I don't seem to get my head round
> so thought I better ask for some good help ;)
>
>
> ...
> foreach ($detailsArray as $details) {
> $counter++;
> foreach ($details as $key => $value) {
>
> $arrayData[] = array(
> 'id'.$counter => $value->getId(),
> 'detail'.$counter => $value->getDetailText()
> );
> }
>
>
>
> rather than an array of array I'd like to have an array containing the
> values all in a flat form
>
> the function should return an array like:
>
> $resultArray = array('id1' =>'1', detail1 => 'ABC', id2 =>'1', detail2 =>
> 'DEF');
>
>
> How am I going to achieve this ?

foreach (…) {
$arrayData['id'.$counter] = $value->getId();
$arrayData['detail'.$counter] = $value->getDetailText();
}

Micha
Re: Problem: Read array of array into flat array [message #170872 is a reply to message #170871] Sat, 04 December 2010 12:23 Go to previous message
gina is currently offline  gina
Messages: 2
Registered: December 2010
Karma: 0
Junior Member
Hallo Micha.

Vielen lieben Dank ... manchmal steh ich einfach aufm Schlauch!!!

Gruß Gina :)

"Michael Fesser" <netizen(at)gmx(dot)de> schrieb im Newsbeitrag
news:67ckf6tt72h3b0vis6vm8v4k4b1fe1b8d8(at)mfesser(dot)de...
> .oO(gina)
>
>> I am having a problem with that array and I don't seem to get my head
>> round
>> so thought I better ask for some good help ;)
>>
>>
>> ...
>> foreach ($detailsArray as $details) {
>> $counter++;
>> foreach ($details as $key => $value) {
>>
>> $arrayData[] = array(
>> 'id'.$counter => $value->getId(),
>> 'detail'.$counter => $value->getDetailText()
>> );
>> }
>>
>>
>>
>> rather than an array of array I'd like to have an array containing the
>> values all in a flat form
>>
>> the function should return an array like:
>>
>> $resultArray = array('id1' =>'1', detail1 => 'ABC', id2 =>'1', detail2 =>
>> 'DEF');
>>
>>
>> How am I going to achieve this ?
>
> foreach (…) {
> $arrayData['id'.$counter] = $value->getId();
> $arrayData['detail'.$counter] = $value->getDetailText();
> }
>
> Micha
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: comp.lang.php
Next Topic: Efficiency of a lot of variables
Goto Forum:
  

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

Current Time: Sun Nov 24 21:46:25 GMT 2024

Total time taken to generate the page: 0.02483 seconds