Create multiple (n) arrays
Posted on
16th Feb 2014 07:03 pm by
admin
Hi there,
I have the following need:
I have 2 arrays (coming from a databases)
Array2 is related to Array1 -
Example:
Array1
Dog, abc
Cat, bcd
Horse, cde
Array2,
meat, abc
bones, abc
fish, bcd
grain, cde
grass, cde
So, I need the array2 split up into separate arrays - but I am will never know in advance how many rows in both arrays there will be.
Basically, I need to display the data so:
Dog
<ul>
<li>meat</li>
<li>bones</li>
</ul>
Cat
<ul>
<li>fish</li>
</ul>
Horse
<ul>
<li>grain</li>
<li>grass</li>
</ul>
As said, the second array will change very often - but will always have the key from the first array
Any help very much appreciated. I do have it sort of working - but EVERY entry from array2 appears under every entry from array1 :-
here is the code that I have so far written:
Code: <?php
$fquestions = $record->getRelatedSet('Markt.FFragen');
$questions = $record->getRelatedSet('FFragen.Fragen');
foreach( $fquestions as $fquestion ) {
$ffrage = $fquestion->getField('Markt.FFragen::fFrage');
$ffgroup = $fquestion->getField('Markt.FFragen::ffgroup');
$ffrageID = $fquestion->getField('Markt.FFragen::ID');
echo'<h3><a href="#">'.$ffrage.'</a></h3>
<div>
<ul>';
foreach( $questions as $question ) {
$frage = $question->getField('FFragen.Fragen::Frage');
$frageID = $question->getField('FFragen.Fragen::ID');
echo '<li>'.$frage.'<div id="slider"></div></li>';
}
echo '</ul>
</div>';
}
?>
Many thanks in advance
No comments posted yet
Your Answer:
Login to answer
274
6
Other forums
convert PHP array to Javascript array
I have a page that gets a request sent from AJAX, and I am trying to convert a PHP array to a javasc
Final year project, please point me in the right direction
hi there for my final year project I'm aiming to build a php script shell to use as an expert system
Searching keywords from array
Hello everyone, Im just wondering if someone could help me with another issue im having. Im still le
Custom CMS
This is a big custom CMS script I'd like to develop and would like some help atleast figuring out wh
output_buffering so rewrite
I'm planning to rewrite some of my scripts so they don't have to use output buffering to accomplish
Executing an exe
Hi. I have some bizarre problem with exec (other any other method) to launch exe's. I am making a ga
Function
How can I make this function that once you click the link in the code it takes you to a new page wit
classic dynpro : hide area and auto adjust hights
Hi,
I want to develop a similar user interface as is used in standard transaction MIGO.
Multi Level Array Problem
hi all,
For example I have array like below:
$temp = array(array('north america', 'us'
Help with form post data and arrays
Hi all,
I am new to this forum... It has been awhile since i have worked with arrays, and i a