Thanks for taking the time to look at this. In your example code won't the $cdata only contain the last value of $safe_item once the loop is finished? I was trying something like your example by the only way I could get each value of $safe_item into the $cdata was to include the $cdata in the loop, which of course creates a new instance of createDataSection with each loop.

Not completely sure, will have to look over and see if possible. The xml being generated is basically a template that a component of Brightscript (for Roku) will read when loading. All elements of the generated xml would never change, only the addChannel and add Item info. The addChannel info is all generated thru a php script I have written that parses out xml info from multiple xml files and puts them together. I had been saving all the info into a json array file and have the Roku read the json array. The creators of Roku have developed a new component that allows developers create screens thru xml templates, one being the one I am working with. I will see if I can create xml nodes and see if this works. Have a feeling the Brightscript component is setup to read the template a certain way and may not recognize the information. Thanks for the idea.

Thank you both for the advice and direction. After restructure of the array into. I'm sure it can be cleaner but I don't know a lot about PHP, only what I have read or found on forums.
0 =>
array (
'start' => '201601221400',
),
1 =>
array (
'time' => '201601221400',
'name' => 'ABC',
'title' => 'FABLife',
'desc' => 'Mark Cuban (``Shark Tank\'\'); top five must-haves; collectors try to guess the prices of celebrity memorabilia; creating a high-end playroom and eliminating toy clutter without breaking the bank.',
),
I was able to parse as needed with the following:
$counter=0;
//CONTROL
foreach ($items as $key=>$value){
echo "NEW CONTROL ".$value['start']."<br>";
foreach ($items as $item=>$time){
if($time['time']==$value['start']){
if(empty($time['time'])){
}else{
$counter=$counter + 1;
$match[]=array(
'time'=>$time['time'],
'title'=>$time['title'],
'desc'=>$time['desc'],
);
if ($counter==5){break;}
if ($counter==5){break;}
}
}
}
$counter=0;
}

Psycho, you are correct in that the array needed to be restructured. I have done this and have the script running as needed. Thanks for the advice but either I didn't communicate my idea well or it was was just not understood. In your solution you break if the count of the $foundvalues==5. This is no good, it will only break for the first array then the count will be more than five. The $foundvalues is never reset so it's count will always be more than 5, correct? I replaced checking the count of the array with a counter that increments by 1. When it reaches 5 it breaks and resets. This gives me exactly what is needed, the first 5 arrays of each array. Thanks again

Thanks for the advice. Psycho, not sure what you mean as to the structure of the array, I thought it was pretty straight forward, one array with three element (time, title, desc). Not going to argue at all about it but I thought my logic kinda follows what you did, of course yours is better since it works. Thank you for you input. Mac_gyver, that's kinda what I wanted to do but I couldn't figure out how to move to next "new" time value in the loop, or get it to move.
Thanks to both for the help.

Trying to build an array from elements taken from another array, which I thought would be easy but not so much. My first step is to create a $control that will be used in a loop later on. I am then looping thru an array file comparing an element's value to the $control. If the same, for testing I am sending it to browser. In code below, $control is already created. The array file I am looping thru has the following structure:
$items=array (
0 =>
array (
'time' => '201601221400',
'title' => 'FABLife',
'desc' => 'Mark Cuban (``Shark Tank\'\'); top five must-haves; collectors try to guess the prices of celebrity memorabilia; creating a high-end playroom and eliminating toy clutter without breaking the bank.',
),
1 =>
array (
'time' => '201601221400',
'title' => 'The First 48',
'desc' => 'A young man is robbed and killed while meeting up with a girl he met earlier; a man is gunned down outside an annual football game.',
),
2 =>
array (
'time' => '201601221400',
'title' => 'Teen Titans Go!',
'desc' => 'Robin makes the other Titans sell their treasured mementos from past adventures.',
),
Note: The number of 'time' elements vary as tho how many have the same value. In the example I posted this particular time element has 3 of the same value, some have more some have less. I want to loop thru the array file, compare the $control to the 'time' value, if equal it will echo to browser. I want the loop to continue for either as long as the $control and 'time' are equal or 5 is reached.
for($i=0; $i< count($control); $i++){
foreach ($items as $item){
while (($items['time']==$control[$i]) || ($r < 5 )){
if ($r > 5){
echo "OUT. . ."."<BR>";
$r=0;
}else{
$r=$r+1;
echo $control[$i]." ". $r."<br>";
}
}
}
}
When this is ran, I get the first 5 values of the first 'time' but then nothing, it's not continuing to the next $control. Can somebody point out my error(s)? Thanks.

Attempting to get a value of an array that's actually inside several arrays, one being multidimensional I do believe. The array has the following structure:
[catalog] => Array (
[0] => Array (
[attributes] => Array (
[book] => 20160122
)
[section] => Array (
[0] => Array (
[id] => F100
[title] => Across the Sea
)
[1] => Array (
[id] => F101
[title] => Blue Water
)
[2] => Array (
[id] => F102
[title] => Red Rove
I have been able to get a return of the values back for each except for the id and title using the following:
foreach($result as $items){
foreach($items['catalog'] as $a){
foreach($a['attributes'] as $b){
foreach($b['section'] as $c){
foreach($c['book'] as $d){
foreach($d['id'] as $e){
print_r($e);
}
}
}
}
}
I can't seem to get the value for the id or title. Any help appreciated.

I am sure this can be done, but I don't know enough about PHP. I am posting all my code with hopes somebody can point me right direction. I am looping thru an xml, parsing a url where I have xml files stored, loading the xml, parsing out the start, title and desc into a control array. I then loop thru the start element comparing its value to the control, if the same it writes it to array along with title and desc. Finally I create one array of the start, title and desc, which will be saved to php array file. I am trying to group all titles (along with desc) by start.
foreach ($items as $load){
$contents[]= simplexml_load_file($load['guide']); //LOAD XML EACH CHANNEL
foreach ($contents as $content){ //BUILD CONTROL ARRAY
$control=array(
'start'=>$content->programme['start'],
'title'=>$content->programme->title,
'desc'=>$content->programme->desc,
);
}
$start[]=$content->programme['start'];
foreach($start as $base){
if($base==$control['start']){ //COMPARE TO CONTROL
echo $base." ".$control['title']."<br>";
$start[]=$control['start'];
$title[]=$control['title'];
$desc[]=$control['title'];
}
foreach($start as $final){
$guide=array(
'start'=>$final['start'],
'title'=>$final['title'],
'desc'=>$final['desc'],
);
}
}