I have this array:
stdClass Object
(
[nid] => 218
[node_title] => This is my title text
[field_data_field_slider_image_delta] => 0
[field_data_field_slider_image_language] => und
[field_data_field_slider_image_bundle] => slider
[field_data_field_slider_image_field_slider_image_fid] => 1278
[field_data_field_slider_image_field_slider_image_alt] =>
[field_data_field_slider_image_field_slider_image_title] =>
[field_data_field_slider_image_field_slider_image_width] => 1180
[field_data_field_slider_image_field_slider_image_height] => 352
[node_created] => 1334267878
[field_data_field_slider_link_node_entity_type] => node
[field_data_body_node_entity_type] => node
[field_data_field_slider_image_node_entity_type] => node
[_field_data] => Array
(
[nid] => Array
(
[entity_type] => node
[entity] => stdClass Object
(
[vid] => 218
[uid] => 1
[title] => This is my title text
[log] =>
[status] => 1
[comment] => 1
[promote] => 1
[sticky] => 0
[nid] => 218
[type] => slider
[language] => en
[created] => 1334267878
[changed] => 1334268388
[tnid] => 0
[translate] => 0
[revision_timestamp] => 1334268388
[revision_uid] => 1
[body] => Array
(
[und] => Array
(
[0] => Array
(
[value] => <p>This is my body text</p>
[summary] =>
[format] => full_html
[safe_value] => <p>This is my body text</p>
[safe_summary] =>
)
)
)
[field_slider_image] => Array
(
[und] => Array
(
[0] => Array
(
[fid] => 1278
[alt] =>
[title] =>
[width] => 1180
[height] => 352
[uid] => 1
[filename] => slider-d.jpg
[uri] => public://images/slider-d.jpg
[filemime] => image/jpeg
[filesize] => 103135
[status] => 1
[timestamp] => 1334267878
[type] => image
)
)
)
[field_slider_link] => Array
(
[und] => Array
(
[0] => Array
(
[url] => http://mydomain.com/my/link
[title] =>
[attributes] => Array
(
)
)
)
)
[cid] => 0
[last_comment_timestamp] => 1334267878
[last_comment_name] =>
[last_comment_uid] => 1
[comment_count] => 0
[name] => admin
[picture] => 1242
[data] => a:2:{s:7:"contact";i:0;s:7:"overlay";i:1;}
)
)
)
[field_field_slider_link] => Array
(
[0] => Array
(
[rendered] => Array
(
[#markup] => http://mydomain.com/my/link
[#access] => 1
)
[raw] => Array
(
[url] => http://mydomain.com/my/link
[title] => http://mydomain.com/my/link
[attributes] => Array
(
)
[display_url] => http://mydomain.com/my/link
)
)
)
[field_body] => Array
(
[0] => Array
(
[rendered] => Array
(
[#markup] => <p>This is my body text</p>
[#access] => 1
[#type] => markup
[#pre_render] => Array
(
[0] => drupal_pre_render_markup
[1] => ctools_dependent_pre_render
)
[#children] => <p>This is my body text</p>
[#printed] => 1
)
[raw] => Array
(
[value] => <p>This is my body text</p>
[summary] =>
[format] => full_html
[safe_value] => <p>This is my body text</p>
[safe_summary] =>
[#children] =>
[#printed] => 1
)
[#children] => <p>This is my body text</p>
[#printed] => 1
)
[#children] => <p>This is my body text</p>
[#printed] => 1
)
[field_field_slider_image] => Array
(
[0] => Array
(
[rendered] => Array
(
[#theme] => image_formatter
[#item] => Array
(
[fid] => 1278
[alt] =>
[title] =>
[width] => 1180
[height] => 352
[uid] => 1
[filename] => slider-d.jpg
[uri] => public://images/slider-d.jpg
[filemime] => image/jpeg
[filesize] => 103135
[status] => 1
[timestamp] => 1334267878
[type] => image
)
[#image_style] => featured_slideshow
[#path] =>
[#access] => 1
)
[raw] => Array
(
[fid] => 1278
[alt] =>
[title] =>
[width] => 1180
[height] => 352
[uid] => 1
[filename] => slider-d.jpg
[uri] => public://images/slider-d.jpg
[filemime] => image/jpeg
[filesize] => 103135
[status] => 1
[timestamp] => 1334267878
[type] => image
)
)
)
)
and I need to get the [url] value (which in this one is http://mydomain.com/my/link)
I tried to follow a tutorial and ended up with this:
print $row->field_field_slider_link[0]['raw']['url']
but I get this error message:
Notice: Undefined offset: 0 in include() (line 57 of /var/www/vhosts/clientname/public_html/sites/all/themes/custom/templates/views/ff-nivo-slider/views-view-fields--ff-nivo-slider.tpl.php).
can anyone see what i'm doing wrong here?
Thanks
C
The array your code runs with is not the one you expect. Check the value of $row->field_field_slider_link. Chances are that it's an empty array.
Related
I just started using moltin and learn to developing it.
In the getting started there is code that to show product
<?php
$product = \Product::Find(['slug' => 'baju']);
?>
documentation link https://moltin.com/getting-started/php
and the result is when I print array
<?php
print_r($product);
?>
It shows like this
Array ( [status] => 1 [result] => Array ( [0] => Array ( [id] => 1207658536885027482 [order] => [created_at] => 2016-03-17 03:08:58 [updated_at] => 2016-03-17 03:08:58 [sku] => baju-1 [title] => baju [slug] => baju [sale_price] => 0 [status] => Array ( [value] => Live [data] => Array ( [key] => 1 [value] => Live ) ) [category] => Array ( [value] => Uncategorized [data] => Array ( [1134518259857490806] => Array ( [id] => 1134518259857490806 [order] => [created_at] => 2015-12-07 05:12:15 [updated_at] => 2015-12-07 05:12:15 [parent] => [slug] => uncategorized [status] => Array ( [value] => Live [data] => Array ( [key] => 1 [value] => Live ) ) [title] => Uncategorized [description] => Products that do not fit into another category ) ) ) [stock_level] => 10 [stock_status] => Array ( [value] => In Stock [data] => Array ( [key] => 1 [value] => In Stock ) ) [description] => baju [requires_shipping] => Array ( [value] => Yes [data] => Array ( [key] => 1 [value] => Yes ) ) [weight] => 0 [height] => 0 [width] => 0 [depth] => 0 [catalog_only] => Array ( [value] => No [data] => Array ( [key] => 0 [value] => No ) ) [tax_band] => Array ( [value] => Default [data] => Array ( [id] => 1134518260142703561 [title] => Default [description] => [rate] => 20 [created_at] => [updated_at] => ) ) [collection] => [brand] => [price] => Array ( [value] => £1.20 [data] => Array ( [formatted] => Array ( [with_tax] => £1.20 [without_tax] => £1.00 [tax] => £0.20 ) [rounded] => Array ( [with_tax] => 1.2 [without_tax] => 1 [tax] => 0.2 ) [raw] => Array ( [with_tax] => 1.2 [without_tax] => 1 [tax] => 0.2 ) ) ) [is_variation] => [modifiers] => Array ( ) [images] => Array ( ) ) ) [pagination] => Array ( [total] => 1 [current] => 1 [limit] => 10 [offset] => 0 [from] => 1 [to] => 1 [offsets] => Array ( [first] => [previous] => [next] => [last] => ) [links] => Array ( [first] => [previous] => [next] => [last] => ) ) ) status = 1
How to get specific array from this list?
I already try
<?php
echo $product[0]['id'];
?>
it didn't work, show error Notice: Undefined offset: 0
you have a multidimensional array under the result key
access it the following way:
$product['result'][0]['id']
Give this a try:
echo $product['result'][0]['id'];
I have this array:
stdClass Object
(
[tid] => 26001835
[vid] => 5
[name] => AppleTV
[description] => My description
[format] => filtered_html
[weight] => 0
[vocabulary_machine_name] => how_to_watch_device
[field_device_image] => Array
(
[und] => Array
(
[0] => Array
(
[fid] => 26608990
[alt] =>
[title] =>
[width] => 194
[height] => 102
[uid] => 26000697
[filename] => Apple-TV.png
[uri] => public://Apple-TV.png
[filemime] => image/png
[filesize] => 2103
[status] => 1
[timestamp] => 1405346182
)
)
)
[field_buy_now_button_link] => Array
(
[und] => Array
(
[0] => Array
(
[value] => http://www.something.com
[format] =>
[safe_value] => http://www.something.com
)
)
)
[field_learn_more] => Array
(
[und] => Array
(
[0] => Array
(
[value] => http://something.com/somepage
[format] =>
[safe_value] => http://something.com/somepage
)
)
)
[field_device_category] => Array
(
[und] => Array
(
[0] => Array
(
[value] => network
)
)
)
)
stdClass Object
(
[tid] => 26001834
[vid] => 5
[name] => Playstation - USA
[description] => My description
[format] => filtered_html
[weight] => 2
[vocabulary_machine_name] => how_to_watch_device
[field_device_image] => Array
(
[und] => Array
(
[0] => Array
(
[fid] => 26608991
[alt] =>
[title] =>
[width] => 194
[height] => 102
[uid] => 26000697
[filename] => ps4network.png
[uri] => public://ps4network.png
[filemime] => image/png
[filesize] => 4566
[status] => 1
[timestamp] => 1405346218
)
)
)
[field_buy_now_button_link] => Array
(
[und] => Array
(
[0] => Array
(
[value] => http://www.somesite.com
[format] =>
[safe_value] => http://somesite.com
)
)
)
[field_learn_more] => Array
(
)
[field_device_category] => Array
(
[und] => Array
(
[0] => Array
(
[value] => blast_areas
)
)
)
)
stdClass Object
(
[tid] => 26001836
[vid] => 5
[name] => Brighthouse Networks
[description] => My description
[format] => filtered_html
[weight] => 3
[vocabulary_machine_name] => how_to_watch_device
[field_device_image] => Array
(
[und] => Array
(
[0] => Array
(
[fid] => 26608993
[alt] =>
[title] =>
[width] => 194
[height] => 102
[uid] => 26000697
[filename] => brighthouse.png
[uri] => public://brighthouse.png
[filemime] => image/png
[filesize] => 8392
[status] => 1
[timestamp] => 1405358781
)
)
)
[field_buy_now_button_link] => Array
(
)
[field_learn_more] => Array
(
)
[field_device_category] => Array
(
[und] => Array
(
[0] => Array
(
[value] => ppv_provider
)
)
)
)
I want to sort the array by the array by the value in field_device_category. Basically, I want to group the results but first I need to make sure all the objects are sorted by field_device_category.
Thanks in advance!
Use usort for this kind of sorting. It uses Quicksort in the background and takes a user-defined function to compare the array elements:
usort($array, "complicatedArrayComparer");
function complicatedArrayComparer($a,$b)
{
if ($a['field_device_category'] == $b['field_device_category']) {
return 0;
}
return ($a['field_device_category'] < $b['field_device_category']) ? -1 : 1;
}
I am using the webform module for Drupal.
I needed to customize one of the webform nodes.
So I tried printing [title] => title of this webform goes here!!! using <?php print drupal_render($form['process']['title']); ?>
But it returns nothing, what am I doing wrong here?
Thanks!
FYI, the form can be rendered with; drupal_render($form['submitted']);
Array ( [#attached] => Array ( [css] => Array ( [0] => sites/all/modules/webform/css/webform.css ) [js] => Array ( [0] => sites/all/modules/webform/js/webform.js ) ) [#process] => Array ( [0] => webform_client_form_includes ) [#node] => stdClass Object ( [vid] => 22 [uid] => 2 [title] => title of this webform goes here!!! [log] => [status] => 1 [comment] => 1 [promote] => 1 [sticky] => 0 [nid] => 22 [type] => webform [language] => en [created] => 1373585579 [changed] => 1374117294 [tnid] => 0 [translate] => 0 [revision_timestamp] => 1374117294 [revision_uid] => 8 [body] => Array ( ) [rdf_mapping] => Array ( [rdftype] => ...
You should try this,
echo $form[#node]->title;
var_dump($form[#node]);// to test it your node data
As from your array
Array (
[#attached] => Array ([css] => Array ( [0] => sites/all/modules/webform/css/webform.css ) [js] => Array ( [0] => sites/all/modules/webform/js/webform.js ))
[#process] => Array ( [0] => webform_client_form_includes )
[#node] => stdClass Object ( [vid] => 22 [uid] => 2 [title] => title of this webform goes here!!! [log] => [status] => 1 [comment] => 1 [promote] => 1 [sticky] => 0 [nid] => 22 [type] => webform [language] => en [created] => 1373585579 [changed] => 1374117294 [tnid] => 0 [translate] => 0 [revision_timestamp] => 1374117294 [revision_uid] => 8 [body] => Array ( ) [rdf_mapping] => Array ( [rdftype] => ...
I am trying to access data inside a php object. I am confused about what the exact stynax is. Here is the output of the object:
stdClass Object ( [vid] => 10 [uid] => 1 [title] => Beachhead Don [log] =>
[status] => 1 [comment] => 1 [promote] => 0 [sticky] => 0 [ds_switch] => [nid] =>
10 [type] => product [language] => und [created] => 1357668665 [changed] => 1358198386
[tnid] => 0 [translate] => 0 [revision_timestamp] => 1358198386 [revision_uid] => 1
[model] => B 3000 [list_price] => 0.00000 [cost] => 0.00000 [sell_price] => 1.00000
[weight] => 0 [weight_units] => lb [length] => 0 [width] => 0 [height] => 0
[length_units] => in [pkg_qty] => 1 [default_qty] => 1 [unique_hash] =>
2eec0fcc8483f3a3541870fb24223296 [ordering] => 0 [shippable] => 0 [price] => 1.00000
[body] => Array ( [und] => Array ( [0] => Array ( [value] => Description info
))))))))))))))))))))))))))))))))))))))0 [summary] => [format] => filtered_html
[safe_value] =>Description info ))))))))))))))))))))))))))))))))))))))0[safe_summary]
=> ) ) ) [uc_product_image] => Array ( [und] => Array ( [0] => Array ( [fid] => 11
[alt] => [title] => [width] => 90 [height] => 120 [uid] => 1 [filename] =>
beachhead_don.jpg [uri] => public://beachhead_don.jpg [filemime] => image/jpeg
[filesize] => 14342 [status] => 1 [timestamp] => 1357668665 [rdf_mapping] => Array ( )
) ) ) [field_author] => Array ( [und] => Array ( [0] => Array ( [value] => John B.
Romesier [format] => [safe_value] => John B. Romesier ) ) ) [field_publisher] => Array
( [und] => Array ( [0] => Array ( [value] => Unknown [format] => [safe_value] =>
Unknown ) ) ) [field_release_date] => Array ( [und] => Array ( [0] => Array ( [value]
=> Mar 2012 [format] => [safe_value] => Mar 2012 ) ) ) [field_number_of_pages] => Array
( [und] => Array ( [0] => Array ( [value] => 123 ) ) ) [field_catagory] => Array (
[und] => Array ( [0] => Array ( [tid] => 4 ) ) ) [field_book_type] => Array ( [und] => Array ( [0] => Array ( [tid] => 1 ) ) ) [field_isbn] => Array ( ) [field_about_the_author] => Array ( [und] => Array ( [0] => Array ( [value] => Beachhed Don authoer............................ [format] => [safe_value] => Beachhed Don authoer............................ ) ) ) [rdf_mapping] => Array ( [rdftype] => Array ( [0] => sioc:Item [1] => foaf:Document ) [title] => Array ( [predicates] => Array ( [0] => dc:title ) ) [created] => Array ( [predicates] => Array ( [0] => dc:date [1] => dc:created ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [changed] => Array ( [predicates] => Array ( [0] => dc:modified ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [body] => Array ( [predicates] => Array ( [0] => content:encoded ) ) [uid] => Array ( [predicates] => Array ( [0] => sioc:has_creator ) [type] => rel ) [name] => Array ( [predicates] => Array ( [0] => foaf:name ) ) [comment_count] => Array ( [predicates] => Array ( [0] => sioc:num_replies ) [datatype] => xsd:integer ) [last_activity] => Array ( [predicates] => Array ( [0] => sioc:last_activity_date ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) ) [cid] => 0 [last_comment_timestamp] => 1357668665 [last_comment_name] => [last_comment_uid] => 1 [comment_count] => 0 [name] => admin [picture] => 0 [data] => b:0; [entity_view_prepared] => 1 )
I am trying to retrive the [value] of Description info ))))))))))))))))))))))))))))))))))))))0
I tried this
<?php
$node = menu_get_object(); //drupal code
if ( !empty($node) ) {
print $node ->body=>und=>0=>value;
}?>
and got an error about the '=' sign. What is the proper way to get my data?
[body] and [und] are arrays, so access them like this:
echo $node->body['und'][0]['value'];
It should be:
$node->body['und'][0]['value']
'Body' and 'und' are Arrays and need to be accessed with array syntax([]).
Accessing these values directly is sometimes frowned upon in drupal. You may want to look into: http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_render/7
[5] => Array
(
[id] => 29372
[product_id] => Array
(
[0] => stdClass Object
(
[id] => 1469
[type_id] => 1
[title] => Hearth 2 Hearth
[cover] => 21cf9d7d09d403251ba5d01ff33cd089.jpg
[coverid] => 1178
[inserted_by] => 0
[inserted_date] => 2011-02-11 13:55:23
[status_id] => 0
)
)
[variable_id] => 9
[variable_value] => 2011-02-11
[master_value] =>
[released_date] => 2011-02-11
[price] => Array
(
[0] => Array
(
[product_id] => 1469
[media_format] => VCD
[price] => 29000
[discount] => 5
)
)
[media_format] => VCD
)
[6] => Array
(
[id] => 30074
[product_id] => Array
(
[0] => stdClass Object
(
[id] => 1470
[type_id] => 1
[title] => Hearth 2 Hearth
[cover] => 149ddd4d1d5e567c1300d4831323e1c5.jpg
[coverid] => 1177
[inserted_by] => 6
[inserted_date] => 2011-02-16 15:18:58
[status_id] => 0
)
)
[variable_id] => 9
[variable_value] => 2011-02-11
[master_value] =>
[released_date] => 2011-02-11
[price] => Array
(
[0] => Array
(
[product_id] => 1470
[media_format] => DVD
[price] => 39000
[discount] => 0
)
)
[media_format] => DVD
)
I want the result by media_format = DVD so the whole array is gone, is there anyway to delete an array or remove it?
The same way you "delete" any variable:
unset($array[$index]);