I have a JSON as shown below present in a file ptp-ess_landing.json.
ptp-ess_landing.json file:
{"toggle_multi_tiles":["1","2","3","4"]}
I have another php file (depth.php) in which I have some css codes.
Inside the depth.php, I have the following php code which makes depth.php and ptp-ess_landing.json to communicate with each other.
if (file_exists('feeds/ptp-ess_landing.json')) {
$data = json_decode(file_get_contents('feeds/ptp-ess_landing.json'));
}
What I want to achieve in depth.php file is,
Case A, When JSON is this {"toggle_multi_tiles":["1","2","3","4"]}
, following CSS should be called:
<style>
.hello-world {
display:block;
}
</style>
Case B, When JSON is this {"toggle_multi_tiles":["1","2","3"]}
, following CSS should be called:
<style>
.hello-world {
display:inline-block;
}
</style>
This is what I have tried:
<style>
<?php if($data->toggle_multi_tiles["1","2","3","4"]) { ?> // Line A
.hello-world {
display:block;
}
<?php } ?>
</style>
<style>
<?php if($data->toggle_multi_tiles["1","2","3"]) { ?> // Line B
.hello-world {
display:inline-block;
}
<?php } ?>
</style>
Problem Statement:
I am getting error at Line A/Line B. I am wondering what changes I should make in the php code above at Line A/Line B so that it goes inside the if block with particular dataset of JSON.
Edit 1:
On doing var_dump($data);
inside depth.php
file, I am getting the following on the webpage ["toggle_multi_tiles"]=> array(4) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" [3]=> string(1) "4" }
On doing print_r($data);
inside depth.php
file I am getting [toggle_multi_tiles] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 )
on the webpage