I have a serialized field in my database. I can get the contents of this field and unserialize them however I am unsure how to get certain values of these. I ultimately need a foreach of each item and value from the data.
In the below example I need to be able to get the following:
Main Image Replacement:
BGL_Burhill_People_AndyHiseman_300dpi_Super-Size-14.JPG Complimentary:
Comp Text Quote Code: Code Text
I need the label as one variable and the value as another within a foreach. These labels and values are variable so I cannot manually get this data by their labels.
array (
0 =>
array (
'mode' => 'builder',
'cssclass' => '',
'hidelabelinorder' => '',
'hidevalueinorder' => '',
'element' =>
array (
'type' => 'radio',
'rules_type' =>
array (
'Reprint_0' =>
array (
0 => '',
),
'Edit Artwork_1' =>
array (
0 => '',
),
),
'_' =>
array (
'price_type' => '',
),
),
'name' => '',
'value' => 'Edit Artwork',
'price' => '',
'section' => '58073632e582b5.35893028',
'section_label' => '',
'percentcurrenttotal' => 0,
'currencies' =>
array (
),
'price_per_currency' =>
array (
'GBP' => '',
),
'quantity' => 1,
'multiple' => '1',
'key' => 'Edit Artwork_1',
'use_images' => '',
'changes_product_image' => '',
'imagesp' => '',
'images' => '',
),
1 =>
array (
'mode' => 'builder',
'cssclass' => '',
'hidelabelinorder' => '',
'hidevalueinorder' => '',
'element' =>
array (
'type' => 'radio',
'rules_type' =>
array (
'BGL_Burhill_People_AndyHiseman_300dpi_Super-Size-14.JPG_0' =>
array (
0 => '',
),
'BGL_Burhill_People_AndyHiseman_300dpi_Super-Size-21.JPG_1' =>
array (
0 => '',
),
'BGL_Burhill_People_AndyHiseman_300dpi_Super-Size-77.JPG_2' =>
array (
0 => '',
),
),
'_' =>
array (
'price_type' => '',
),
),
'name' => 'Main Image Replacement',
'value' => 'BGL_Burhill_People_AndyHiseman_300dpi_Super-Size-14.JPG',
'price' => '',
'section' => '58073632e582d2.46631826',
'section_label' => 'Main Image Replacement',
'percentcurrenttotal' => 0,
'currencies' =>
array (
),
'price_per_currency' =>
array (
'GBP' => '',
),
'quantity' => 1,
'multiple' => '1',
'key' => 'BGL_Burhill_People_AndyHiseman_300dpi_Super-Size-14.JPG_0',
'use_images' => 'images',
'changes_product_image' => '',
'imagesp' => '',
'images' => 'http://burhill.immaculate.co.uk/wp-content/uploads/2016/10/BGL_Burhill_People_AndyHiseman_300dpi_Super-Size-14-150x150.jpg',
),
2 =>
array (
'mode' => 'builder',
'cssclass' => 'col-6',
'hidelabelinorder' => '',
'hidevalueinorder' => '',
'element' =>
array (
'type' => 'textfield',
'rules_type' =>
array (
0 =>
array (
0 => '',
),
),
'_' =>
array (
'price_type' => '',
),
),
'name' => 'Complimentary',
'value' => 'Comp Text',
'price' => '',
'section' => '58073632e582f4.32183997',
'section_label' => 'Complimentary',
'percentcurrenttotal' => 0,
'currencies' =>
array (
),
'price_per_currency' =>
array (
),
'quantity' => 1,
),
3 =>
array (
'mode' => 'builder',
'cssclass' => 'col-6',
'hidelabelinorder' => '',
'hidevalueinorder' => '',
'element' =>
array (
'type' => 'textfield',
'rules_type' =>
array (
0 =>
array (
0 => '',
),
),
'_' =>
array (
'price_type' => '',
),
),
'name' => 'Quote Code',
'value' => 'Code Text',
'price' => '',
'section' => '58073632e58317.46363272',
'section_label' => 'Quote Code',
'percentcurrenttotal' => 0,
'currencies' =>
array (
),
'price_per_currency' =>
array (
),
'quantity' => 1,
),
)
foreach($your_array as $key => $value) {
$your_value = $value['value'];
$your_label = $value['section_label'];
}
This should work for you as long as i got the right keys there.
Related
I am a complete beginner in PHP. However I know how to output the value of custom field. I am having a bit of problems with arrays. The post meta key is fw_options. The value has multiple arrays and looks like this:
array (
0 =>
array (
'featured_post' => false,
'featured_expiry' => '',
'_featured_book_string' => '0',
'reading_level' => 'medium',
'reading_type' =>
array (
'time' => 'fixed',
'hourly' =>
array (
'hourly_read' => '',
'estimated_hours' => '',
),
'fixed' =>
array (
'reading_times' => '500',
),
),
'reading_duration' => 'one_month',
'english_level' => 'fluent',
'readers_level' => 'starter',
'expiry_date' => '2019/12/31',
'show_attachments' => 'off',
'read_documents' =>
array (
),
'address' => '',
'longitude' => '',
'latitude' => '',
'country' =>
array (
0 => '717',
),
),
)
I have this code which I have tried with no success:
$array = get_post_meta( get_the_ID(), 'fw_options', true );
echo $array[0]['reading_type']['fixed']['reading_times'];
How can I output the value 500 from the post meta key reading_times?
Simple Print array according to key
First hold the value into a variable than print according to array key
$data = array(
'featured_post' => false,
'featured_expiry' => '',
'_featured_book_string' => '0',
'reading_level' => 'medium',
'reading_type' =>
array(
'time' => 'fixed',
'hourly' =>
array(
'hourly_read' => '',
'estimated_hours' => '',
),
'fixed' =>
array(
'reading_times' => '500',
),
),
'reading_duration' => 'one_month',
'english_level' => 'fluent',
'readers_level' => 'starter',
'expiry_date' => '2019/12/31',
'show_attachments' => 'off',
'read_documents' =>array(),
'address' => '',
'longitude' => '',
'latitude' => '',
'country' =>
array(
0 => '717',
),
);
echo $data['reading_type']['fixed']['reading_times'];
Output #500
I have this code (created from the admin side) in my wordpress Database postmeta table.
a:28:{s:12:"featuredItem";s:1:"0";s:10:"headerType";s:5:"image";s:11:"headerImage";s:60:"https://rocks---.de/wp-content/uploads/2018/08/IMG_2051.jpg";s:16:"headerImageAlign";s:10:"image-left";s:3:"map";a:7:{s:7:"address";s:6:"Goslar";s:8:"latitude";s:10:"51.9059531";s:9:"longitude";s:18:"10.428996299999994";s:10:"streetview";s:1:"0";s:9:"swheading";s:2:"90";s:7:"swpitch";s:1:"5";s:6:"swzoom";s:1:"1";}s:9:"telephone";s:4:"0221";s:19:"telephoneAdditional";a:3:{i:0;a:1:{s:6:"number";s:12:"111111111111";}i:1;a:1:{s:6:"number";s:13:"2222222222222";}i:2;a:1:{s:6:"number";s:13:"3333333333333";}}s:5:"email";s:20:"goslarEmail#email.de";s:9:"showEmail";s:1:"1";s:15:"contactOwnerBtn";s:1:"1";s:3:"web";s:27:"https://musicheadquarter.de";s:12:"webLinkLabel";s:17:"Label of the Link";s:19:"displayOpeningHours";s:1:"1";s:18:"openingHoursMonday";s:2:"12";s:19:"openingHoursTuesday";s:2:"12";s:21:"openingHoursWednesday";s:2:"12";s:20:"openingHoursThursday";s:2:"12";s:18:"openingHoursFriday";s:2:"12";s:20:"openingHoursSaturday";s:2:"12";s:18:"openingHoursSunday";s:2:"12";s:16:"openingHoursNote";s:26:"Text zu den Öffnungsziten";s:18:"displaySocialIcons";s:1:"1";s:26:"socialIconsOpenInNewWindow";s:1:"1";s:11:"socialIcons";a:2:{i:0;a:4:{s:5:"image";s:0:"";s:4:"icon";s:18:"fa-facebook-square";s:9:"iconColor";s:7:"#00FF00";s:4:"link";s:22:"http://rocks---.de";}i:1;a:4:{s:5:"image";s:0:"";s:4:"icon";s:12:"fa-instagram";s:9:"iconColor";s:7:"#00FF00";s:4:"link";s:20:"https://rocks---.de";}}s:14:"displayGallery";s:1:"1";s:7:"gallery";a:3:{i:0;a:2:{s:5:"title";s:6:"Bild 1";s:5:"image";s:60:"https://rocks---.de/wp-content/uploads/2019/01/IMG_8797.jpg";}i:1;a:2:{s:5:"title";s:6:"Bild 2";s:5:"image";s:60:"https://rocks---.de/wp-content/uploads/2019/01/IMG_8443.jpg";}i:2;a:2:{s:5:"title";s:6:"Bild 3";s:5:"image";s:60:"https://rocks---.de/wp-content/uploads/2018/08/IMG_8545.jpg";}}s:15:"displayFeatures";s:1:"1";s:8:"features";a:2:{i:0;a:3:{s:4:"icon";s:0:"";s:4:"text";s:15:"Feature Titel 1";s:4:"desc";s:28:"Feature Titel Beschreibung 1";}i:1;a:3:{s:4:"icon";s:0:"";s:4:"text";s:15:"Feature Titel 2";s:4:"desc";s:28:"Feature Titel Beschreibung 2";}}}
Now I tried to create the code for this ARRAY or what it is called. Everything works fine, exept the ARRAY in an ARRAY thing. Like, the list of social icons, image galelry and telephone numbers.
This is what I have so far:
$data = array(
'subtitle' => 'Utertitel',
'featuredItem' => '0',
'headerType' => 'image',
'headerImage' => 'https://rocks---.de/wp-content/uploads/slide3___beach-2179183_1920.jpg',
'headerHeight' => '375',
'map' => array(
'address' => $adresse,
'latitude' => $lat,
'longitude' => $lng,
'streetview' => '0',
'swheading' => '90',
'swpitch' => '5',
'swzoom' => '14'
),
'telephone' => '0221',
'telephoneAdditional' => '0228',
'email' => 'meister#rocks---.de',
'showEmail' => '1',
'contactOwnerBtn' => '1',
'web' => 'https://musicheadquarter.de',
'webLinkLabel' => '',
'displayOpeningHours' => '1',
'openingHoursMonday' => '12-17',
'openingHoursTuesday' => '12-17',
'openingHoursWednesday' => '12-17',
'openingHoursThursday' => '12-17',
'openingHoursFriday' => '12-17',
'openingHoursSaturday' => '12-17',
'openingHoursSunday' => '12-17',
'openingHoursNote' => 'Zusatzinfos zu den Öffnungszeiten',
'displaySocialIcons' => '0',
'socialIconsOpenInNewWindow' => '1',
'socialIcons' => array(
'icon' => 'fa-facebook-square',
'link' => 'https://rocks---.de'
),
'displayGallery' => '0',
'gallery' => array(
'title' => 'Titel des Bildes',
'image' => 'https://rocks---.de/wp-content/uploads/slide3___beach-2179183_1920.jpg'
),
'displayFeatures' => '0',
'features' => '0'
);
/* $data = maybe_serialize( $data ); */
update_post_meta( $post_id, '_ait-item_item-data', $data );
HOw do I create the ARRAY for the Images, social icons and telephone numbers.
I unserialized the Field Data and it shows the ARRAY, great!
array (
'featuredItem' => '0',
'headerType' => 'image',
'headerImage' => 'https://rockspots.de/wp-content/uploads/2018/08/IMG_2051.jpg',
'headerImageAlign' => 'image-left',
'map' =>
array (
'address' => 'Goslar',
'latitude' => '51.9059531',
'longitude' => '10.428996299999994',
'streetview' => '0',
'swheading' => '90',
'swpitch' => '5',
'swzoom' => '1',
),
'telephone' => '0221',
'telephoneAdditional' =>
array (
0 =>
array (
'number' => '111111111111',
),
1 =>
array (
'number' => '2222222222222',
),
2 =>
array (
'number' => '3333333333333',
),
),
'email' => 'goslarEmail#email.de',
'showEmail' => '1',
'contactOwnerBtn' => '1',
'web' => 'https://musicheadquarter.de',
'webLinkLabel' => 'Label of the Link',
'displayOpeningHours' => '1',
'openingHoursMonday' => '12',
'openingHoursTuesday' => '12',
'openingHoursWednesday' => '12',
'openingHoursThursday' => '12',
'openingHoursFriday' => '12',
'openingHoursSaturday' => '12',
'openingHoursSunday' => '12',
'openingHoursNote' => 'Text zu den Öffnungsziten',
'displaySocialIcons' => '1',
'socialIconsOpenInNewWindow' => '1',
'socialIcons' =>
array (
0 =>
array (
'image' => '',
'icon' => 'fa-facebook-square',
'iconColor' => '#00FF00',
'link' => 'http://festivaldate.de',
),
1 =>
array (
'image' => '',
'icon' => 'fa-instagram',
'iconColor' => '#00FF00',
'link' => 'https://rockspots.de',
),
),
'displayGallery' => '1',
'gallery' =>
array (
0 =>
array (
'title' => 'Bild 1',
'image' => 'https://rockspots.de/wp-content/uploads/2019/01/IMG_8797.jpg',
),
1 =>
array (
'title' => 'Bild 2',
'image' => 'https://rockspots.de/wp-content/uploads/2019/01/IMG_8443.jpg',
),
2 =>
array (
'title' => 'Bild 3',
'image' => 'https://rockspots.de/wp-content/uploads/2018/08/IMG_8545.jpg',
),
),
'displayFeatures' => '1',
'features' =>
array (
0 =>
array (
'icon' => '',
'text' => 'Feature Titel 1',
'desc' => 'Feature Titel Beschreibung 1',
),
1 =>
array (
'icon' => '',
'text' => 'Feature Titel 2',
'desc' => 'Feature Titel Beschreibung 2',
),
),
)
Now I need to know, how to create this part of the array. The number of images for the gallery is not fixed.
'gallery' =>
array (
0 =>
array (
'title' => 'Bild 1',
'image' => 'https://rockspots.de/wp-content/uploads/2019/01/IMG_8797.jpg',
),
1 =>
array (
'title' => 'Bild 2',
'image' => 'https://rockspots.de/wp-content/uploads/2019/01/IMG_8443.jpg',
),
2 =>
array (
'title' => 'Bild 3',
'image' => 'https://rockspots.de/wp-content/uploads/2018/08/IMG_8545.jpg',
),
),
Thanks for some tips,
Denis
This question already has answers here:
How can I sort arrays and data in PHP?
(14 answers)
Closed 4 years ago.
How do you make someone who has a higher subscriberCount be sorted to the top? For example, I want to list the top 50 by subscriberCount. Currently it just sorts by the order added to $topchan1["items"]. I need to order by the highest subscriberCount.
$topchan1 = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/channels?id='
.$kanalas1.'&part=snippet%2Cstatistics&key='.$API.''),true);
$videoList = array_merge($topchan1["items"],$topchan2["items"],$topchan3["items"],$topchan4["items"]);
foreach ($videoList as $key => $part) {
$sort[$key] = sort($part['statistics']['subscriberCount']);
}
array_multisort($sort, SORT_DESC, $videoList);
$i = 1;
for( $i = 0 ; $i <= count($videoList)-1 ; $i++ )
{
if(isset($videoList[$i]["statistics"]["subscriberCount"])) {
echo $videoList[$i]["statistics"]["subscriberCount"].' _ ';
}
}
how looks
array ( 0 => array ( 'kind' => 'youtube#channel', 'etag' => '"XI7nbFXulYBIpL0ayR_gDh3eu1k/Wj45BU6eiZOcR9nLVG4cXvflUNY"', 'id' => 'UCgQ1CeGtjCbkvslmG3zTAFA', 'snippet' => array ( 'title' => 'ILYA STREKAL', 'description' => 'Привет, меня зовут Илья Стрекаловский, добро пожаловать на мой канал!', 'customUrl' => 'BayanCover', 'publishedAt' => '2013-01-13T15:44:18.000Z', 'thumbnails' => array ( 'default' => array ( 'url' => 'https://yt3.ggpht.com/a-/AN66SAytpuX_75kGnsI5bvr_EkGTeQtZy3AJJXfH2w=s88-mo-c-c0xffffffff-rj-k-no', 'width' => 88, 'height' => 88, ), 'medium' => array ( 'url' => 'https://yt3.ggpht.com/a-/AN66SAytpuX_75kGnsI5bvr_EkGTeQtZy3AJJXfH2w=s240-mo-c-c0xffffffff-rj-k-no', 'width' => 240, 'height' => 240, ), 'high' => array ( 'url' => 'https://yt3.ggpht.com/a-/AN66SAytpuX_75kGnsI5bvr_EkGTeQtZy3AJJXfH2w=s800-mo-c-c0xffffffff-rj-k-no', 'width' => 800, 'height' => 800, ), ), 'localized' => array ( 'title' => 'ILYA STREKAL', 'description' => 'Привет, меня зовут Илья Стрекаловский, добро пожаловать на мой канал!', ), 'country' => 'RU', ), 'statistics' => array ( 'viewCount' => '234688406', 'commentCount' => '0', 'subscriberCount' => '2254032', 'hiddenSubscriberCount' => false, 'videoCount' => '153', ), ),
1 => array ( 'kind' => 'youtube#channel', 'etag' => '"XI7nbFXulYBIpL0ayR_gDh3eu1k/1vk-0WWcl2cpv1LO_4WQGsb2Qhk"', 'id' => 'UCMnOYmqiAQhE51l6AzEuOBA', 'snippet' => array ( 'title' => '', 'customUrl' => 'yanshelestx', 'publishedAt' => '2016-01-08T13:06:33.000Z', 'thumbnails' => array ( 'default' => array ( 'url' => 'https://yt3.ggpht.com/a-/AN66SAx6VddPszhqRGnHG48L5wVzTyf-h9lFa4F9Ig=s88-mo-c-c0xffffffff-rj-k-no', 'width' => 88, 'height' => 88, ), 'medium' => array ( 'url' => 'https://yt3.ggpht.com/a-/AN66SAx6VddPszhqRGnHG48L5wVzTyf-h9lFa4F9Ig=s240-mo-c-c0xffffffff-rj-k-no', 'width' => 240, 'height' => 240, ), 'high' => array ( 'url' => 'https://yt3.ggpht.com/a-/AN66SAx6VddPszhqRGnHG48L5wVzTyf-h9lFa4F9Ig=s800-mo-c-c0xffffffff-rj-k-no', 'width' => 800, 'height' => 800, ), ), 'defaultLanguage' => 'ru', 'localized' => array ( 'title' => 'Shelest', 'description' => 'Hello! This channel is dedicated to high-tech. I\'m a big lover of quality products for an adequate cost. The channel will express the personal opinion of the purchased goods and to listen to your words. Thank you!', ), 'country' => 'UA', ), 'statistics' => array ( 'viewCount' => '53038697', 'commentCount' => '0', 'subscriberCount' => '404844', 'hiddenSubscriberCount' => false, 'videoCount' => '123', ), ),
2 => array ( 'kind' => 'youtube#channel', 'etag' => '"XI7nbFXulYBIpL0ayR_gDh3eu1k/sSeA4B5B1NeVdRrLvhV6IQk9AJs"', 'id' => 'UCEFpNxeybzVwRbnYabQsXEg', 'snippet' => array ( 'title' => 'Bass Music Movement', 'description' => 'Music Promotion & Record Label Submissions/Business inquiries: bassmusicmovement#outlook.com', 'customUrl' => 'brazilianbassmovement', 'publishedAt' => '2017-03-06T02:48:38.000Z', 'thumbnails' => array ( 'default' => array ( 'url' => 'https://yt3.ggpht.com/a-/AN66SAx25V8TX9UzZkzfLlHPFH9yFjxQQQFeILTi=s88-mo-c-c0xffffffff-rj-k-no', 'width' => 88, 'height' => 88, ), 'medium' => array ( 'url' => 'https://yt3.ggpht.com/a-/AN66SAx25V8TX9UzZkzfLlHPFH9yFjxQQQFeILTi=s240-mo-c-c0xffffffff-rj-k-no', 'width' => 240, 'height' => 240, ), 'high' => array ( 'url' => 'https://yt3.ggpht.com/a-/AN66SAx25V8TX9UzZkzfLlHPFH9yFjxQQQFeILTi=s800-mo-c-c0xffffffff-rj-k-no', 'width' => 800, 'height' => 800, ), ), 'localized' => array ( 'title' => 'Bass Music Movement', 'description' => 'Music Promotion & Record Label Submissions/Business inquiries: bassmusicmovement#outlook.com', ), 'country' => 'BR', ), 'statistics' => array ( 'viewCount' => '136215709', 'commentCount' => '0', 'subscriberCount' => '748023', 'hiddenSubscriberCount' => false, 'videoCount' => '46', ), ),
3 => array ( 'kind' => 'youtube#channel', 'etag' => '"XI7nbFXulYBIpL0ayR_gDh3eu1k/VwnSAHbLaj-RwQW8QKFECxplCp4"', 'id' => 'UCAf-RYRpQgxpj8voC29ck7w', 'snippet' => array ( 'title' => 'Hard Play', 'description' => '', 'customUrl' => 'hardplaygamechannel', 'publishedAt' => '2016-06-23T20:39:00.000Z', 'thumbnails' => array ( 'default' => array ( 'url' => '', 'width' => 88, 'height' => 88, ), 'medium' => array ( 'url' => 'https://yt3.ggpht.com/a-/AN66SAyu2XfSQsqjyNqu-fTTjleD9XzLSLoLsP-8Yw=s240-mo-c-c0xffffffff-rj-k-no', 'width' => 240, 'height' => 240, ), 'high' => array ( 'url' => 'https://yt3.ggpht.com/a-/AN66SAyu2XfSQsqjyNqu-fTTjleD9XzLSLoLsP-8Yw=s800-mo-c-c0xffffffff-rj-k-no', 'width' => 800, 'height' => 800, ), ), 'localized' => array ( 'title' => 'Hard Play', 'description' => '', ), 'country' => 'RU', ), 'statistics' => array ( 'viewCount' => '39723260', 'commentCount' => '0', 'subscriberCount' => '784162', 'hiddenSubscriberCount' => false, 'videoCount' => '260', ), ), )
You need to use usort() with custome function where you can compare viewCount and sort array in DESC order
function sortByviewCount($a, $b) {
return ($a['statistics']['viewCount'] > $b['statistics']['viewCount']) ? -1:1;
}
usort($videoList, 'sortByviewCount');
print_r($videoList);
Output:-https://3v4l.org/HqXVc
Hopping some of you can help me with this, since a few days back I'm trying to get a list like a carousel, displayed in my FaceBook bot using the following code:
public function returnCarousel(){
$messagearray = array (
'message' =>
array (
'attachment' =>
array (
'type' => 'list',
'payload' =>
array (
'template_type' => 'list',
'top_element_style' => 'compact',
'elements' =>
array (
0 =>
array (
'title' => 'Classic T-Shirt Collection',
'subtitle' => 'See all our colors',
'image_url' => 'https://peterssendreceiveapp.ngrok.io/img/collection.png',
'buttons' =>
array (
0 =>
array (
'title' => 'View',
'type' => 'web_url',
'url' => 'https://peterssendreceiveapp.ngrok.io/collection',
'messenger_extensions' => true,
'webview_height_ratio' => 'tall',
'fallback_url' => 'https://peterssendreceiveapp.ngrok.io/',
),
),
),
1 =>
array (
'title' => 'Classic White T-Shirt',
'subtitle' => 'See all our colors',
'default_action' =>
array (
'type' => 'web_url',
'url' => 'https://peterssendreceiveapp.ngrok.io/view?item=100',
'messenger_extensions' => false,
'webview_height_ratio' => 'tall',
),
),
2 =>
array (
'title' => 'Classic Blue T-Shirt',
'image_url' => 'https://peterssendreceiveapp.ngrok.io/img/blue-t-shirt.png',
'subtitle' => '100% Cotton, 200% Comfortable',
'default_action' =>
array (
'type' => 'web_url',
'url' => 'https://peterssendreceiveapp.ngrok.io/view?item=101',
'messenger_extensions' => true,
'webview_height_ratio' => 'tall',
'fallback_url' => 'https://peterssendreceiveapp.ngrok.io/',
),
'buttons' =>
array (
0 =>
array (
'title' => 'Shop Now',
'type' => 'web_url',
'url' => 'https://peterssendreceiveapp.ngrok.io/shop?item=101',
'messenger_extensions' => true,
'webview_height_ratio' => 'tall',
'fallback_url' => 'https://peterssendreceiveapp.ngrok.io/',
),
),
),
),
'buttons' =>
array (
0 =>
array (
'title' => 'View More',
'type' => 'postback',
'payload' => 'payload',
),
),
),
),
),
);
$this->sendMessage($messagearray);
}
public function sendMessage($parameters) {
echo json_encode($parameters);
}
No carousel is displayed and no error is returnes intead I get in my ngrok console this:
{"message":{"attachment":{"type":"list","payload":{"template_type":"list","top_element_style":"compact","elements":[{"title":"Classic T-Shirt Collection","subtitle":"See all our colors","image_url":"https://peterssendreceiveapp.ngrok.io/img/collection.png","buttons":[{"title":"View","type":"web_url","url":"https://peterssendreceiveapp.ngrok.io/collection","messenger_extensions":true,"webview_height_ratio":"tall","fallback_url":"https://peterssendreceiveapp.ngrok.io/"}]},{"title":"Classic White T-Shirt","subtitle":"See all our colors","default_action":{"type":"web_url","url":"https://peterssendreceiveapp.ngrok.io/view?item=100","messenger_extensions":false,"webview_height_ratio":"tall"}},{"title":"Classic Blue T-Shirt","image_url":"https://peterssendreceiveapp.ngrok.io/img/blue-t-shirt.png","subtitle":"100% Cotton, 200% Comfortable","default_action":{"type":"web_url","url":"https://peterssendreceiveapp.ngrok.io/view?item=101","messenger_extensions":true,"webview_height_ratio":"tall","fallback_url":"https://peterssendreceiveapp.ngrok.io/"},"buttons":[{"title":"Shop Now","type":"web_url","url":"https://peterssendreceiveapp.ngrok.io/shop?item=101","messenger_extensions":true,"webview_height_ratio":"tall","fallback_url":"https://peterssendreceiveapp.ngrok.io/"}]}],"buttons":[{"title":"View More","type":"postback","payload":"payload"}]}}}}
if I send a single card it works, please your help
SOLVED: I formatted the array like this and I get it working.
$messagearray = array (
'speech' => 'Carousel',
'messages' => array (
0 => array (
'type' => 1,
'platform' => 'facebook',
'title' => 'Rosa Amarilla',
'imageUrl' => 'http://rosa.com/assets/imgs/rosaamarilla.jpg',
'buttons' =>
array (
0 =>array ('text' => 'Detalles de la Rosa', 'postback' => '',),
),
),
1 =>array (
'type' => 1,
'platform' => 'facebook',
'title' => 'Rosa Azul',
'imageUrl' => 'http://rosa.com/assets/imgs/rosaazul.jpg',
'buttons' =>
array (
0 => array ('text' => 'Detalles de la Rosa', 'postback' => '',),
),
),
),);
How to check double fields in multidimensional array?
My array:
array (
'welcome' =>
array (
0 =>
array (
'url' => '/strona-powitalna',
'component' => 'welcome',
'action' => 'getForumPosts',
'parameter' =>
array (
0 =>
array (
'name' => '',
'type' => '',
'default' => '',
'method' => '',
),
),
'parameters_all' => '1',
'parameters_get' => 0,
'parameters_post' => 0,
),
),
'logi' =>
array (
),
'main' =>
array (
0 =>
array (
'url' => '/refresh',
'component' => 'main',
'action' => 'refreshPlayer',
'contype' => 'AJAX',
'parameter' =>
array (
0 =>
array (
'name' => '',
'type' => '',
'default' => '',
'method' => '',
),
),
'parameters_all' => '1',
'parameters_get' => 0,
'parameters_post' => 0,
),
),
'account' =>
array (
0 =>
array (
'url' => '/zmien-kolor',
'component' => 'account',
'action' => 'changeColorName',
'contype' => 'COMMON',
'parameter' =>
array (
0 =>
array (
'name' => 'rgb',
'type' => 'string',
'default' => '',
'method' => 'POST',
),
),
'parameters_all' => '1',
'parameters_get' => 0,
'parameters_post' => 1,
),
1 =>
array (
'url' => '/kolor-nicku',
'component' => 'account',
'action' => 'colorName',
'contype' => 'COMMON',
'parameter' =>
array (
0 =>
array (
'name' => '',
'type' => '',
'default' => '',
'method' => '',
),
),
'parameters_all' => '1',
'parameters_get' => 0,
'parameters_post' => 0,
)));
I must check if parameter url is unique.
foreach($arrays as $array)
if(is_array($array))
foreach($array as $key => $data)
if(strcmp($key,'url') == 0 && strcmp($key,$url) == 0){
echo $url.' is not unique url!';
break;
}
where $url variable is the url that you are looking for in arrays.