I have a foreach loop what works fine but i need to call it a few time within the same page to get different results so i thought a function would be better but i keep getting Warning: Invalid argument supplied for foreach()
heres the code that works
$weaponSlot = '1';
$talentGridHash = $json2['Response']['data']['buckets']['Equippable'][''.$weaponSlot.'']['items']['0']['talentGridHash'];
$nodes = $json2['Response']['data']['buckets']['Equippable'][''.$weaponSlot.'']['items']['0']['nodes'];
foreach($nodes as $talentNode) {
// Perform operations on each nodes...
if($talentNode['isActivated'] && $talentNode['state'] === 10){
$nodesActive[] = $talentNode;
$perkName = $json2['Response']['definitions']['talentGrids'][''.$talentGridHash.'']['nodes'][''.$talentNode['nodeHash'].'']['steps']['0']['nodeStepName'];
$perkIcon = $json2['Response']['definitions']['talentGrids'][''.$talentGridHash.'']['nodes'][''.$talentNode['nodeHash'].'']['steps']['0']['icon'];
if (strpos($perkName, 'Damage') == false) {
$perkOutput .= '<div style="border:1px solid #999; border-radius:3px; padding:1px; float:left; margin-right:8px"><img src="http://www.example.com'.$perkIcon.'" height="22" title='.$perkName.'" /></div>';
}
}
}
echo $perkOutput;
heres the code into a function...have i missed something?? (BTW this is the first time ive done a function, looked at examples online)
$perkOutput = null;
function getItemPerks($weaponSlot){
$talentGridHash = $json2['Response']['data']['buckets']['Equippable'][''.$weaponSlot.'']['items']['0']['talentGridHash'];
$nodes = $json2['Response']['data']['buckets']['Equippable'][''.$weaponSlot.'']['items']['0']['nodes'];
foreach($nodes as $talentNode) {
// Perform operations on each nodes...
if($talentNode['isActivated'] && $talentNode['state'] === 10){
$nodesActive[] = $talentNode;
$perkName = $json2['Response']['definitions']['talentGrids'][''.$talentGridHash.'']['nodes'][''.$talentNode['nodeHash'].'']['steps']['0']['nodeStepName'];
$perkIcon = $json2['Response']['definitions']['talentGrids'][''.$talentGridHash.'']['nodes'][''.$talentNode['nodeHash'].'']['steps']['0']['icon'];
if (strpos($perkName, 'Damage') == false) {
$perkOutput .= '<div style="border:1px solid #999; border-radius:3px; padding:1px; float:left; margin-right:8px"><img src="http://www.example.com'.$perkIcon.'" height="22" title='.$perkName.'" /></div>';
}
}
}
return $perkOutput;
}
getItemPerks(1);