PHP Error - Really Need Help

Hi guys, I’m having some problem with my PHP code, I’ve been having this problem for the past two days and have a deadline to meet (tomorrow) so I’m really trying to fix this ASAP. I’m trying to get a JSON file to be loaded then decoded, then I need to go through the array that’s built (which is what I’m using the while loop for) then I need to check if a field is a certain value (what I’m using the if statement for). My code is below. Any help is appreciated:

[php] <?
$proj = json_decode(file_get_contents(‘data/new.json’));
$projdata = get_object_vars($proj);
$count = count($proj);
//print_r($proj);
$musthaves = array();
$strategics = array();
$products = array();
$musthaveproj = array();
for($i=0; $i <= $count; $i++) {
$filter = $projdata[$i];
$if = ($filter[‘type’] == ‘Must-Have’ ? array_push($musthaves, $filter));
// if($filter[‘type’] == ‘Strategic’) array_push($strategics, $projdata);
// if($filter[‘type’] == ‘Product’) array_push($products, $projdata);

				}

				//print_r($musthaveproj);
				$count1 = count($musthaves);$count2 = count($strategics);$count3 = count($products);
				//echo ($count1);echo ($count2);echo ($count3);
				print_r($musthaves);
				
				//print_r($projdata[0]['devcapacity']);
				
				echo ("		
					<script type='javascript/text'>
						(function(){
							var graphDefinition = {
								categories : ['test1', 'test2', 'test3'],
								dataset: {"."'test1':[{".$musthaveproj[0]['id'])."
							}
							var chartObject = uv.chart('StackedBar', graphDefinition, optionalConfiguration)
						});
					</script>";?>[/php]

You might want to tell us what the problem is.

The problem is that I can’t use my if loops inside my while or if lops so I’ll write

[php]
for($i=0; $i <= $count; $i++) {
$filter = $projdata[$i];
$if = ($filter[‘type’] == ‘Must-Have’ ? array_push($musthaves, $filter));
// if($filter[‘type’] == ‘Strategic’) array_push($strategics, $projdata);
// if($filter[‘type’] == ‘Product’) array_push($products, $projdata);

				}

[/php]

The error is Unexpected ‘)’ on line xx (referring to the line that $if is on.
If I do

[php]
$I=0;
$count=count($proj);
while($i <= $count){
$filter = $projdata[$i];
if($filter[‘type’] == ‘Strategic’) array_push($strategics, $projdata);
// if($filter[‘type’] == ‘Product’) array_push($products, $projdata);

				}

[/php]
My error will be Unexpected T_IF ‘if’ on line xx referring to the line with the if. So I’m completely unable to add any logic, I checked my PHP version and everything.

At least one problem, you wrote the Ternary incorrectly here:

$if = ($filter[‘type’] == ‘Must-Have’ ? array_push($musthaves, $filter));

Sponsor our Newsletter | Privacy Policy | Terms of Service