My array displays properly but I would like for the link inside to display the current value of the array.
Here is my code:
foreach( $persons as $pid => $p)
{
echo '<a href="?tag=">' . implode( '</a>, <a href="?tag=">', $tags[ $p['id'] ]) . '</a>';
echo '<br /><br />';
}
This is what I want to display:
<a href="?tag=tag1">tag1</a>, <a href="?tag=tag2">tag2</a>
UPDATE
I got the answer elsewhere. Turns out it was pretty simple. Going to accept answer that’s helped me improve on my code.
$tags_arr = $tags[$p['id']];
foreach($tags_arr as $v){
$out[] = "<a href='?tag=$v'>$v</a>";
}
I’m assuming
$tagsis an array itself, and you are attempting to write out each tag for each$p['id']. If I have it correct, don’t useimplode()for this. Instead use two foreach loops.UPDATE
I see some problems here:
Above, you set the
titleandheightarray keys to$persons[$row['id']]. Following that though, you overwrite the whole$persons[$row['id']]with a newarray(). Instead since you’re keeping the same array keys you can simply use:Now where I believe the most serious problem is:
By using the
[]notation, you are appending$row['tag']onto the$tags[ $row['id']as an array element rather than setting its value to the tag. That’s the reason you’re gettingArray(1)in place of the tag value. Instead use: