0

Hello, I am getting a weird error when i try to run this array:

//leafly api keys
$appID ='Blah';
$appKEY = 'blah';

//init curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://data.leafly.com/strains/".strtolower($data)); //change the strain dynamically of course for your app
curl_setopt($ch,CURLOPT_HTTPHEADER,array('APP_ID:'.$appID,'APP_KEY:'.$appKEY));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);

//Clean it into an php array object and set var
$cleaned_response = json_decode($output,true);
foreach($cleaned_response as $image){
    //continue;
echo'<img height="100" width="100" src="'.$image['photos'].'"/>'; //<--Line 73
}
// Look at it

print_r($cleaned_response);
// close curl resource to free up system resources
$output = curl_init();

then when i run the script, i get this:

<b>Warning</b>:  Illegal string offset 'thumb' in <b>C:\xampp\htdocs\~review\search1.php</b> on line <b>73</b><br />

The array that is returned is:

array(25) { ["sl_translate"]=> string(37) "description,descriptionPlain,category" ["id"]=> int(239) ["slug"]=> string(9) "pineapple" ["name"]=> string(9) "Pineapple" ["symbol"]=> string(3) "Pin" ["category"]=> string(6) "Hybrid" ["description"]=> string(247) "

Pineapple marijuana strain is a phenotype F2 of the ERSB indica Pineapple that was inbred and feminized. The buds smell like the actual fruit of pineapple and even tend to resemble the fruit when growing. Flowering time is 7-8 weeks. 
" ["descriptionPlain"]=> string(240) "Pineapple marijuana strain is a phenotype F2 of the ERSB indica Pineapple that was inbred and feminized. The buds smell like the actual fruit of pineapple and even tend to resemble the fruit when growing. Flowering time is 7-8 weeks.  " ["aka"]=> NULL ["rating"]=> float(3.9) ["reviewCount"]=> int(70) ["flavors"]=> array(5) { [0]=> array(2) { ["name"]=> string(9) "Pineapple" ["score"]=> float(62.237394957983) } [1]=> array(2) { ["name"]=> string(5) "Sweet" ["score"]=> float(35.136554621849) } [2]=> array(2) { ["name"]=> string(8) "Tropical" ["score"]=> float(22.111344537815) } [3]=> array(2) { ["name"]=> string(7) "Pungent" ["score"]=> float(14.443277310924) } [4]=> array(2) { ["name"]=> string(6) "Earthy" ["score"]=> float(9.453781512605) } } ["effects"]=> array(5) { [0]=> array(2) { ["name"]=> string(5) "Happy" ["score"]=> float(98.203419298754) } [1]=> array(2) { ["name"]=> string(7) "Relaxed" ["score"]=> float(89.338235294118) } [2]=> array(2) { ["name"]=> string(8) "Euphoric" ["score"]=> float(87.393146913938) } [3]=> array(2) { ["name"]=> string(8) "Uplifted" ["score"]=> float(76.494132135613) } [4]=> array(2) { ["name"]=> string(6) "Hungry" ["score"]=> float(60.111199652275) } } ["symptoms"]=> array(5) { [0]=> array(2) { ["name"]=> string(6) "Stress" ["score"]=> float(45.631700956245) } [1]=> array(2) { ["name"]=> string(4) "Pain" ["score"]=> float(24.199507389163) } [2]=> array(2) { ["name"]=> string(10) "Depression" ["score"]=> float(20.876195305708) } [3]=> array(2) { ["name"]=> string(6) "Nausea" ["score"]=> float(20.198855404231) } [4]=> array(2) { ["name"]=> string(8) "Insomnia" ["score"]=> float(17.920530281078) } } ["conditions"]=> array(5) { [0]=> array(2) { ["name"]=> string(7) "Anxiety" ["score"]=> float(39.906911040278) } [1]=> array(2) { ["name"]=> string(8) "ADD/ADHD" ["score"]=> float(12.132352941176) } [2]=> array(2) { ["name"]=> string(9) "Migraines" ["score"]=> float(7.0197044334975) } [3]=> array(2) { ["name"]=> string(4) "PTSD" ["score"]=> float(4.4642857142857) } [4]=> array(2) { ["name"]=> string(9) "Arthritis" ["score"]=> float(2.6785714285714) } } ["negatives"]=> array(5) { [0]=> array(2) { ["name"]=> string(9) "Dry Mouth" ["score"]=> float(33.839829035062) } [1]=> array(2) { ["name"]=> string(8) "Dry Eyes" ["score"]=> float(14.593596059113) } [2]=> array(2) { ["name"]=> string(5) "Dizzy" ["score"]=> float(11.516589394378) } [3]=> array(2) { ["name"]=> string(8) "Headache" ["score"]=> float(4.987684729064) } [4]=> array(2) { ["name"]=> string(8) "Paranoid" ["score"]=> float(3.8793103448276) } } ["articlesAvailable"]=> bool(true) 

["photos"]=> array(4) { [0]=> array(3) { ["uploaded"]=> string(21) "/Date(1412910713961)/" ["thumb"]=> string(70) "http://leafly.blob.core.windows.net/reviews/pineapple_100x100_7461.jpg" ["fullsize"]=> string(90) "http://d3odcnigi1nnzz.cloudfront.net/cdn/strain-photo/200302/b/pineapple__primary_6bd8.jpg" } [1]=> array(3) { ["uploaded"]=> string(21) "/Date(1411943182488)/" ["thumb"]=> string(70) "http://leafly.blob.core.windows.net/reviews/pineapple_100x100_8a6d.jpg" ["fullsize"]=> string(90) "http://d3odcnigi1nnzz.cloudfront.net/cdn/strain-photo/194765/b/pineapple__primary_7c28.jpg" } [2]=> array(3) { ["uploaded"]=> string(21) "/Date(1411869502007)/" ["thumb"]=> string(70) "http://leafly.blob.core.windows.net/reviews/pineapple_100x100_e04b.jpg" ["fullsize"]=> string(90) "http://d3odcnigi1nnzz.cloudfront.net/cdn/strain-photo/194634/b/pineapple__primary_f551.jpg" } [3]=> array(3) { ["uploaded"]=> string(21) "/Date(1408810977356)/" ["thumb"]=> string(70) "http://leafly.blob.core.windows.net/reviews/pineapple_100x100_b38d.jpg" ["fullsize"]=> string(89) "http://d3odcnigi1nnzz.cloudfront.net/cdn/strain-photo/177162/b/pineapple_825x550_8b43.jpg" } } 


["popularCities"]=> array(10) { [0]=> string(11) "Portland,OR" [1]=> string(9) "Eugene,OR" [2]=> string(14) "Los Angeles,CA" [3]=> string(10) "Seattle,WA" [4]=> string(2) "CA" [5]=> string(10) "Spokane,WA" [6]=> string(9) "Tacoma,WA" [7]=> string(10) "Barstow,CA" [8]=> string(7) "Bend,OR" [9]=> string(11) "Berkeley,CA" } ["permalink"]=> string(38) "http://www.leafly.com/hybrid/pineapple" ["starImage"]=> string(45) "//d3odcnigi1nnzz.cloudfront.net/stars/3.9/240" ["testGraph"]=> NULL ["weakDescription"]=> bool(false) ["parents"]=> array(0) { } ["growInfo"]=> array(8) { ["difficulty"]=> NULL ["preferredMedium"]=> NULL ["floweringDays"]=> int(0) ["outdoorFinish"]=> NULL ["height"]=> NULL ["averageYield"]=> NULL ["environment"]=> NULL ["growNotes"]=> string(0) "" } } 

I seperated the photo array element.

I am not sure what i am doing wrong here. Seems to be the correct structure for it...

2
Contributors
2
Replies
34
Views
3 Years
Discussion Span
Last Post by broj1
0

better array structure

Array
(
    [0] => Array
        (
            [sl_translate] => description,descriptionPlain,category
            [id] => 239
            [slug] => pineapple
            [name] => Pineapple
            [symbol] => Pin
            [category] => Hybrid
            [description] => <p>Pineapple marijuana strain is a phenotype F2 of the ERSB indica Pineapple that was inbred and feminized. The buds smell like the actual fruit of pineapple and even tend to resemble the fruit when growing. Flowering time is 7-8 weeks.&nbsp;</p>

            [descriptionPlain] => Pineapple marijuana strain is a phenotype F2 of the ERSB indica Pineapple that was inbred and feminized. The buds smell like the actual fruit of pineapple and even tend to resemble the fruit when growing. Flowering time is 7-8 weeks.&nbsp;

            [aka] => 
            [rating] => 3.9
            [reviewCount] => 70
            [flavors] => Array
                (
                    [0] => Array
                        (
                            [name] => Pineapple
                            [score] => 62.237394957983
                        )

                    [1] => Array
                        (
                            [name] => Sweet
                            [score] => 35.136554621849
                        )

                    [2] => Array
                        (
                            [name] => Tropical
                            [score] => 22.111344537815
                        )

                    [3] => Array
                        (
                            [name] => Pungent
                            [score] => 14.443277310924
                        )

                    [4] => Array
                        (
                            [name] => Earthy
                            [score] => 9.453781512605
                        )

                )

            [effects] => Array
                (
                    [0] => Array
                        (
                            [name] => Happy
                            [score] => 98.203419298754
                        )

                    [1] => Array
                        (
                            [name] => Relaxed
                            [score] => 89.338235294118
                        )

                    [2] => Array
                        (
                            [name] => Euphoric
                            [score] => 87.393146913938
                        )

                    [3] => Array
                        (
                            [name] => Uplifted
                            [score] => 76.494132135613
                        )

                    [4] => Array
                        (
                            [name] => Hungry
                            [score] => 60.111199652275
                        )

                )

            [symptoms] => Array
                (
                    [0] => Array
                        (
                            [name] => Stress
                            [score] => 45.631700956245
                        )

                    [1] => Array
                        (
                            [name] => Pain
                            [score] => 24.199507389163
                        )

                    [2] => Array
                        (
                            [name] => Depression
                            [score] => 20.876195305708
                        )

                    [3] => Array
                        (
                            [name] => Nausea
                            [score] => 20.198855404231
                        )

                    [4] => Array
                        (
                            [name] => Insomnia
                            [score] => 17.920530281078
                        )

                )

            [conditions] => Array
                (
                    [0] => Array
                        (
                            [name] => Anxiety
                            [score] => 39.906911040278
                        )

                    [1] => Array
                        (
                            [name] => ADD/ADHD
                            [score] => 12.132352941176
                        )

                    [2] => Array
                        (
                            [name] => Migraines
                            [score] => 7.0197044334975
                        )

                    [3] => Array
                        (
                            [name] => PTSD
                            [score] => 4.4642857142857
                        )

                    [4] => Array
                        (
                            [name] => Arthritis
                            [score] => 2.6785714285714
                        )

                )

            [negatives] => Array
                (
                    [0] => Array
                        (
                            [name] => Dry Mouth
                            [score] => 33.839829035062
                        )

                    [1] => Array
                        (
                            [name] => Dry Eyes
                            [score] => 14.593596059113
                        )

                    [2] => Array
                        (
                            [name] => Dizzy
                            [score] => 11.516589394378
                        )

                    [3] => Array
                        (
                            [name] => Headache
                            [score] => 4.987684729064
                        )

                    [4] => Array
                        (
                            [name] => Paranoid
                            [score] => 3.8793103448276
                        )

                )

            [articlesAvailable] => 1
            [photos] => Array
                (
                    [0] => Array
                        (
                            [uploaded] => /Date(1412910713961)/
                            [thumb] => http://leafly.blob.core.windows.net/reviews/pineapple_100x100_7461.jpg
                            [fullsize] => http://d3odcnigi1nnzz.cloudfront.net/cdn/strain-photo/200302/b/pineapple__primary_6bd8.jpg
                        )

                    [1] => Array
                        (
                            [uploaded] => /Date(1411943182488)/
                            [thumb] => http://leafly.blob.core.windows.net/reviews/pineapple_100x100_8a6d.jpg
                            [fullsize] => http://d3odcnigi1nnzz.cloudfront.net/cdn/strain-photo/194765/b/pineapple__primary_7c28.jpg
                        )

                    [2] => Array
                        (
                            [uploaded] => /Date(1411869502007)/
                            [thumb] => http://leafly.blob.core.windows.net/reviews/pineapple_100x100_e04b.jpg
                            [fullsize] => http://d3odcnigi1nnzz.cloudfront.net/cdn/strain-photo/194634/b/pineapple__primary_f551.jpg
                        )

                    [3] => Array
                        (
                            [uploaded] => /Date(1408810977356)/
                            [thumb] => http://leafly.blob.core.windows.net/reviews/pineapple_100x100_b38d.jpg
                            [fullsize] => http://d3odcnigi1nnzz.cloudfront.net/cdn/strain-photo/177162/b/pineapple_825x550_8b43.jpg
                        )

                )

            [popularCities] => Array
                (
                    [0] => Portland,OR
                    [1] => Eugene,OR
                    [2] => Los Angeles,CA
                    [3] => Seattle,WA
                    [4] => CA
                    [5] => Spokane,WA
                    [6] => Tacoma,WA
                    [7] => Barstow,CA
                    [8] => Bend,OR
                    [9] => Berkeley,CA
                )

            [permalink] => http://www.leafly.com/hybrid/pineapple
            [starImage] => //d3odcnigi1nnzz.cloudfront.net/stars/3.9/240
            [testGraph] => 
            [weakDescription] => 
            [parents] => Array
                (
                )

            [growInfo] => Array
                (
                    [difficulty] => 
                    [preferredMedium] => 
                    [floweringDays] => 0
                    [outdoorFinish] => 
                    [height] => 
                    [averageYield] => 
                    [environment] => 
                    [growNotes] => 
                )

        )

)
<br />
<b>Notice</b>:  Undefined index: fullsize in <b>C:\xampp\htdocs\~review\search1.php</b> on line <b>75</b><br />
<img height="100" width="100" src=""/></div>
           <hr>
    </div>
        <div class="reslt">
    <h3 id="resuil-title"><a href="strain.php?strain=1">Pineapple Express</a></h3>
        <span class="highlight">Pineapple Express was bred by G13 labs and is the child of Trainwreck and Hawaii. The smell has been likened to fresh apple and mango, with a taste of pineapple, pine and cedar. This hard-hitting sativa provides an energetic high up to 2 hours and has a THC content up to 17% with CBD of 0.17%. Pineapple Express is a marijuana strain with light green buds that are dense with thick resin. </span>
        <div>Array
(
    [0] => Array
        (
            [sl_translate] => description,descriptionPlain,category
            [id] => 239
            [slug] => pineapple
            [name] => Pineapple
            [symbol] => Pin
            [category] => Hybrid
            [description] => <p>Pineapple marijuana strain is a phenotype F2 of the ERSB indica Pineapple that was inbred and feminized. The buds smell like the actual fruit of pineapple and even tend to resemble the fruit when growing. Flowering time is 7-8 weeks.&nbsp;</p>

            [descriptionPlain] => Pineapple marijuana strain is a phenotype F2 of the ERSB indica Pineapple that was inbred and feminized. The buds smell like the actual fruit of pineapple and even tend to resemble the fruit when growing. Flowering time is 7-8 weeks.&nbsp;

            [aka] => 
            [rating] => 3.9
            [reviewCount] => 70
            [flavors] => Array
                (
                    [0] => Array
                        (
                            [name] => Pineapple
                            [score] => 62.237394957983
                        )

                    [1] => Array
                        (
                            [name] => Sweet
                            [score] => 35.136554621849
                        )

                    [2] => Array
                        (
                            [name] => Tropical
                            [score] => 22.111344537815
                        )

                    [3] => Array
                        (
                            [name] => Pungent
                            [score] => 14.443277310924
                        )

                    [4] => Array
                        (
                            [name] => Earthy
                            [score] => 9.453781512605
                        )

                )

            [effects] => Array
                (
                    [0] => Array
                        (
                            [name] => Happy
                            [score] => 98.203419298754
                        )

                    [1] => Array
                        (
                            [name] => Relaxed
                            [score] => 89.338235294118
                        )

                    [2] => Array
                        (
                            [name] => Euphoric
                            [score] => 87.393146913938
                        )

                    [3] => Array
                        (
                            [name] => Uplifted
                            [score] => 76.494132135613
                        )

                    [4] => Array
                        (
                            [name] => Hungry
                            [score] => 60.111199652275
                        )

                )

            [symptoms] => Array
                (
                    [0] => Array
                        (
                            [name] => Stress
                            [score] => 45.631700956245
                        )

                    [1] => Array
                        (
                            [name] => Pain
                            [score] => 24.199507389163
                        )

                    [2] => Array
                        (
                            [name] => Depression
                            [score] => 20.876195305708
                        )

                    [3] => Array
                        (
                            [name] => Nausea
                            [score] => 20.198855404231
                        )

                    [4] => Array
                        (
                            [name] => Insomnia
                            [score] => 17.920530281078
                        )

                )

            [conditions] => Array
                (
                    [0] => Array
                        (
                            [name] => Anxiety
                            [score] => 39.906911040278
                        )

                    [1] => Array
                        (
                            [name] => ADD/ADHD
                            [score] => 12.132352941176
                        )

                    [2] => Array
                        (
                            [name] => Migraines
                            [score] => 7.0197044334975
                        )

                    [3] => Array
                        (
                            [name] => PTSD
                            [score] => 4.4642857142857
                        )

                    [4] => Array
                        (
                            [name] => Arthritis
                            [score] => 2.6785714285714
                        )

                )

            [negatives] => Array
                (
                    [0] => Array
                        (
                            [name] => Dry Mouth
                            [score] => 33.839829035062
                        )

                    [1] => Array
                        (
                            [name] => Dry Eyes
                            [score] => 14.593596059113
                        )

                    [2] => Array
                        (
                            [name] => Dizzy
                            [score] => 11.516589394378
                        )

                    [3] => Array
                        (
                            [name] => Headache
                            [score] => 4.987684729064
                        )

                    [4] => Array
                        (
                            [name] => Paranoid
                            [score] => 3.8793103448276
                        )

                )

            [articlesAvailable] => 1
            [photos] => Array
                (
                    [0] => Array
                        (
                            [uploaded] => /Date(1412910713961)/
                            [thumb] => http://leafly.blob.core.windows.net/reviews/pineapple_100x100_7461.jpg
                            [fullsize] => http://d3odcnigi1nnzz.cloudfront.net/cdn/strain-photo/200302/b/pineapple__primary_6bd8.jpg
                        )

                    [1] => Array
                        (
                            [uploaded] => /Date(1411943182488)/
                            [thumb] => http://leafly.blob.core.windows.net/reviews/pineapple_100x100_8a6d.jpg
                            [fullsize] => http://d3odcnigi1nnzz.cloudfront.net/cdn/strain-photo/194765/b/pineapple__primary_7c28.jpg
                        )

                    [2] => Array
                        (
                            [uploaded] => /Date(1411869502007)/
                            [thumb] => http://leafly.blob.core.windows.net/reviews/pineapple_100x100_e04b.jpg
                            [fullsize] => http://d3odcnigi1nnzz.cloudfront.net/cdn/strain-photo/194634/b/pineapple__primary_f551.jpg
                        )

                    [3] => Array
                        (
                            [uploaded] => /Date(1408810977356)/
                            [thumb] => http://leafly.blob.core.windows.net/reviews/pineapple_100x100_b38d.jpg
                            [fullsize] => http://d3odcnigi1nnzz.cloudfront.net/cdn/strain-photo/177162/b/pineapple_825x550_8b43.jpg
                        )

                )

            [popularCities] => Array
                (
                    [0] => Portland,OR
                    [1] => Eugene,OR
                    [2] => Los Angeles,CA
                    [3] => Seattle,WA
                    [4] => CA
                    [5] => Spokane,WA
                    [6] => Tacoma,WA
                    [7] => Barstow,CA
                    [8] => Bend,OR
                    [9] => Berkeley,CA
                )

            [permalink] => http://www.leafly.com/hybrid/pineapple
            [starImage] => //d3odcnigi1nnzz.cloudfront.net/stars/3.9/240
            [testGraph] => 
            [weakDescription] => 
            [parents] => Array
                (
                )

            [growInfo] => Array
                (
                    [difficulty] => 
                    [preferredMedium] => 
                    [floweringDays] => 0
                    [outdoorFinish] => 
                    [height] => 
                    [averageYield] => 
                    [environment] => 
                    [growNotes] => 
                )

        )

)
1

It is a lot of code but as it seems the $image[photos] is an array of photos that you should iterate through, something like:

foreach($cleaned_response as $image){
    foreach($image[photos] as $oneImage) {
        echo'<img height="100" width="100" src="'.$oneImage['fullsize'].'"/>'
    }
}

Edited by broj1

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.