PHP get all values from specific key from array+object - php
I get an object like this from a SOAP web service:
object(stdClass)#2 (1) {
["tasks"]=>
array(3) {
[0]=>
object(stdClass)#3 (9) {
["externalId"]=>
string(0) ""
["name"]=>
string(10) "Customer A"
["description"]=>
string(0) ""
["bookable"]=>
bool(true)
["billable"]=>
bool(true)
["subtasks"]=>
array(2) {
[0]=>
object(stdClass)#4 (9) {
["externalId"]=>
string(1) "2"
["name"]=>
string(5) "Job 1"
["description"]=>
string(0) ""
["bookable"]=>
bool(true)
["billable"]=>
bool(true)
["subtasks"]=>
object(stdClass)#5 (9) {
["externalId"]=>
string(0) ""
["name"]=>
string(7) "Job 1.1"
["description"]=>
string(0) ""
["bookable"]=>
bool(true)
["billable"]=>
bool(true)
["subtasks"]=>
array(2) {
[0]=>
object(stdClass)#6 (8) {
["externalId"]=>
string(0) ""
["name"]=>
string(9) "Job 1.1.1"
["description"]=>
string(0) ""
["bookable"]=>
bool(true)
["billable"]=>
bool(true)
["customField1"]=>
string(0) ""
["customField2"]=>
string(0) ""
["customField3"]=>
string(0) ""
}
[1]=>
object(stdClass)#7 (8) {
["externalId"]=>
string(0) ""
["name"]=>
string(9) "Job 1.1.2"
["description"]=>
string(0) ""
["bookable"]=>
bool(true)
["billable"]=>
bool(true)
["customField1"]=>
string(0) ""
["customField2"]=>
string(0) ""
["customField3"]=>
string(0) ""
}
}
["customField1"]=>
string(0) ""
["customField2"]=>
string(0) ""
["customField3"]=>
string(0) ""
}
["customField1"]=>
string(0) ""
["customField2"]=>
string(0) ""
["customField3"]=>
string(0) ""
}
[1]=>
object(stdClass)#8 (9) {
["externalId"]=>
string(0) ""
["name"]=>
string(5) "Job 2"
["description"]=>
string(0) ""
["bookable"]=>
bool(true)
["billable"]=>
bool(true)
["subtasks"]=>
object(stdClass)#9 (8) {
["externalId"]=>
string(2) "55"
["name"]=>
string(7) "Job 2.1"
["description"]=>
string(0) ""
["bookable"]=>
bool(true)
["billable"]=>
bool(true)
["customField1"]=>
string(0) ""
["customField2"]=>
string(0) ""
["customField3"]=>
string(0) ""
}
["customField1"]=>
string(0) ""
["customField2"]=>
string(0) ""
["customField3"]=>
string(0) ""
}
}
["customField1"]=>
string(0) ""
["customField2"]=>
string(0) ""
["customField3"]=>
string(0) ""
}
[1]=>
object(stdClass)#10 (8) {
["externalId"]=>
string(3) "123"
["name"]=>
string(10) "Customer B"
["description"]=>
string(0) ""
["bookable"]=>
bool(true)
["billable"]=>
bool(true)
["customField1"]=>
string(0) ""
["customField2"]=>
string(0) ""
["customField3"]=>
string(0) ""
}
[2]=>
object(stdClass)#11 (9) {
["externalId"]=>
string(0) ""
["name"]=>
string(10) "Customer C"
["description"]=>
string(0) ""
["bookable"]=>
bool(true)
["billable"]=>
bool(true)
["subtasks"]=>
object(stdClass)#12 (8) {
["externalId"]=>
string(3) "918"
["name"]=>
string(5) "Job 1"
["description"]=>
string(0) ""
["bookable"]=>
bool(true)
["billable"]=>
bool(true)
["customField1"]=>
string(0) ""
["customField2"]=>
string(0) ""
["customField3"]=>
string(0) ""
}
["customField1"]=>
string(0) ""
["customField2"]=>
string(0) ""
["customField3"]=>
string(0) ""
}
}
}
I need only a stupid function to check every element of externalId.
if( ["externalId"] != "")
{
echo "value found! ".["externalId"]."<br>";
}
I tried to use array_walk_recursive but the object is a mix of arrays and objects.
Compare the ["subtasks"]-elements...
Also tried SOAP_SINGLE_ELEMENT_ARRAYS in the SOAP-call with no difference.
Is there some "magic"? I think the solution is pretty simple, but don't get it yet :-(
Keep in mind: there is no limit of recursively level - every ["subtasks"] can contains more ["subtasks"].
Thank you
Try this
<?php
/**
* #param \stdClass $root
*
* #return array
*/
function externalIdentifiersFrom(\stdClass $root)
{
static $properties = [
'tasks',
'subtasks',
];
$identifiers = [];
if (property_exists($root, 'externalId')
&& is_string($root->externalId)
&& '' !== trim($root->externalId)
) {
$identifiers[] = $root->externalId;
}
foreach ($properties as $property) {
if (property_exists($root, $property) && is_array($root->{$property})) {
$objects = $root->{$property};
foreach ($objects as $object) {
if (!$object instanceof \stdClass) {
continue;
}
$identifiers = array_merge(
$identifiers,
externalIdentifiersFrom($object)
);
}
}
}
return array_unique($identifiers);
}
var_dump(externalIdentifiersFrom($object));
Related
PDO SELECT only selecting first in foreach loop
I am trying to select multiple products from my database and inserting the id into another table. I have tried doing as below and if I just echo $name, $_POST["txtMaterial"][$key] and $_POST["txtSize"][$key] before the query, I get all selected names, materials and sizes, but when I bind the values in the query, I only get the first one. foreach($_POST["txtName"] as $key => $name){ $sQuery = $db->prepare('SELECT id FROM products WHERE name = :sName AND material = :sMaterial AND size = :sSize'); $sQuery->bindValue(':sName', $name); $sQuery->bindValue(':sMaterial', $_POST["txtMaterial"][$key]); $sQuery->bindValue(':sSize', $_POST["txtSize"][$key]); $sQuery->execute(); $aOrders = $sQuery->fetchAll(); foreach($aOrders as $aOrder){ echo print_r($aOrders); } } The print_r of $aOrders is this: "Array ( [id] => 174 ) 1" Which is the first id that I need. Can anyone help me out how to get all the id's? var_dump of $_POST["txtName"] before the foreach: "array(50) { [0]=> string(0) "" [1]=> string(6) "BACURI" [2]=> string(0) "" [3]=> string(0) "" [4]=> string(0) "" [5]=> string(0) "" [6]=> string(0) "" [7]=> string(0) "" [8]=> string(0) "" [9]=> string(0) "" [10]=> string(0) "" [11]=> string(0) "" [12]=> string(0) "" [13]=> string(0) "" [14]=> string(0) "" [15]=> string(0) "" [16]=> string(0) "" [17]=> string(0) "" [18]=> string(0) "" [19]=> string(0) "" [20]=> string(0) "" [21]=> string(0) "" [22]=> string(0) "" [23]=> string(0) "" [24]=> string(0) "" [25]=> string(0) "" [26]=> string(0) "" [27]=> string(0) "" [28]=> string(0) "" [29]=> string(6) "CAJARI" [30]=> string(0) "" [31]=> string(0) "" [32]=> string(0) "" [33]=> string(0) "" [34]=> string(0) "" [35]=> string(0) "" [36]=> string(0) "" [37]=> string(0) "" [38]=> string(0) "" [39]=> string(0) "" [40]=> string(0) "" [41]=> string(0) "" [42]=> string(0) "" [43]=> string(0) "" [44]=> string(0) "" [45]=> string(0) "" [46]=> string(0) "" [47]=> string(0) "" [48]=> string(0) "" [49]=> string(0) "" } " var_dump of $_POST["txtMaterial"] before foreach: "array(2) { [0]=> string(1) "3" [1]=> string(1) "2" } " var_dump of $_POST["txtSize"] before foreach: "array(2) { [0]=> string(2) "20" [1]=> string(1) "4" } "
According provided information you getting one record ID because the only time when you prepare your statement and it is not empty is the second iteration of the loop. You have only 2 keys in associated arrays txtMaterial and txtSize, the any next ones will return null. Take a look here: First loop Your prepared statement will looks like this: SELECT id FROM products WHERE name = "" AND material = 3 AND size = 20 this statement will return an empty array Second loop SELECT id FROM products WHERE name = "BACURI" AND material = 2 AND size = 4 This will end up with result what you get. Array with one record ID = 174. Any next iteration... SELECT id FROM products WHERE name = "" AND material = NULL AND size = NULL This will return an empty array Here is the test: $name = ["", "BACURI", ""]; $material = ["3", "2"]; $size = ["20", "4"]; foreach($name as $key => $val){ echo "\n"; var_dump($val); var_dump($material[$key]); var_dump($size[$key]); } Output string(0) "" string(1) "3" string(2) "20" string(6) "BACURI" string(1) "2" string(1) "4" string(0) "" NULL NULL Hope it helps.
The value becomes blank when loop the array
I get the data from API and the structure like this [ {keyword: ["123","456","789"] , name :"hello" }, {keyword: ["abc","def","ghi"] , name :"bye" }, {keyword: ["987","654","321"] , name :"hello" } ] I decode it and use for loop to process the data for($i = 0, $l = count($result); $i < $l; ++$i) { echo join(',' , $result[0]->keyword); } and i got ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, the i try to dump the array in the loop , the result is array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(0) "" } array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(0) "" } array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } array(2) { [0]=> string(0) "" [1]=> string(0) "" } But I can use the data out of the loop echo join(',' , $result[0]->keyword); //123,456,789 var_dump($result[0]->keyword); //array(3) { [0]=> string(6) "XXXXXXX" [1]=> string(9) "XXXXXXXX" [2]=> string(12) "XXXXXXXXXX" } All other data in the data can be used and no encoding problem, why only this array's content being blank?
You can use a foreach loop here to achieve the desired result. Try this: foreach ( $result as $array ) { echo implode(",", $array->keyword); } Note: most people will use implode, join is simply an alias for implode. It's fine to use either in your code.
Check this code, may be fix your problem <?php $str = '[{"keyword": ["123","456","789"] , "name" :"hello" }, {"keyword": ["abc","def","ghi"] , "name" :"bye" }, {"keyword": ["987","654","321"] , "name" :"hello" }]'; $obj = json_decode($str); foreach($obj as $elem){ echo implode(",",$elem->keyword)."\n"; } ?> live demo : https://eval.in/790394
Extract value from serialized data using php
I have many entries in my database similar to this: s:4075:"{"submitted_values":{"15":"","13":{"13.2":"","13.3":"Me","13.4":"","13.6":"McGee","13.8":""},"14":{"14.2":"","14.3":"You","14.4":"","14.6":"McGoo","14.8":""},"23":"","178":"CST","191":["","","pm"],"192":["","","pm"],"19":"","18":{"18.1":"","18.2":"","18.3":"","18.4":"","18.5":"","18.6":"United States","18_copy_values_activated":false},"20":{"20.1":"","20.2":"","20.3":"","20.4":"","20.5":"","20.6":"United States","20_copy_values_activated":true},"21":{"21.1":"","21.2":"","21.3":"","21.4":"","21.5":"","21.6":"United States","21_copy_values_activated":true},"22":{"22.1":"","22.2":"","22.3":"","22.4":"","22.5":"","22.6":"United States","22_copy_values_activated":true},"151":[{"Name":"","Position":"","Phone Number":"","Email":""}],"193":[""],"148":{"148.1":"","148.2":"","148.3":"","148.4":"","148.5":"","148.6":"","148.7":""},"149":[{"Name":"","Instrument":""}],"150":"","24":"","25":"","26":"","29":"","30":["","","pm"],"31":["","","pm"],"33":["","","pm"],"159":"","34":"","37":["","","am"],"39":"","40":"","32":"","41":"","42":"","170":["","","pm"],"43":"","180":"","44":"","46":"","62":"","160":"","50":"","47":"","48":"","51":"","52":"","53":"","54":"","55":"","181":"","56":"","57":"","141":"","142":"","58":"","59":"","60":"","61":"","196":"","63":"","64":"","65":"","67":"","66":"","161":{"161.1":"","161.2":"","161.3":""},"190":"","158":"","69":"","27":"","71":"","28":"","72":["","","pm"],"73":["","","pm"],"164":"","76":["","","pm"],"162":"","163":"","77":["","","pm"],"182":"","78":"","152":"","153":"","82":"","146":{"146.1":"","146.2":"","146.3":""},"157":"","79":"","83":"","84":"","85":"","86":["","","pm"],"87":["","","pm"],"88":["","","pm"],"89":"","95":[{"Name":"","Phonetic Spelling":"","Order":""}],"166":"","90":"","165":"","185":"","186":"","183":"","184":"","92":["","","pm"],"187":"","96":["","","pm"],"94":[{"Name":"","Relation":""}],"97":"","188":["","","pm"],"98":[{"Name":"","Phonetic Spelling":""}],"99":"","100":"","154":"","155":"","103":"","102":"","104":"","105":"","106":"","107":["","","pm"],"108":[{"Dancers":"","Relationship":"","Song\/Artist":"","Live\/DJ":""}],"167":"","168":"","109":"","110":"","111":"","112":"","113":"","114":"","115":"","169":"","116":[{"Song Title":"","Artist":"","Live\/DJ":""}],"117":"","118":"","119":"","120":"","156":"","147":"","121":"","122":"","123":"","124":"","189":"","179":"","126":"","127":"","128":["","","pm"],"129":["","","pm"],"130":["","","pm"],"131":"","132":"","133":"","134":[{"Wireless Name":"","Password":""}],"135":"","144":[{"College\/University Song":""}],"137":"","145":"","194":"","195":"","173":"","174":"","175":"","171":"","172":"","139":"","176":"50","197":"admin","198":null},"partial_entry":{"id":null,"post_id":null,"date_created":null,"form_id":4,"ip":"104.235.99.179","source_url":"example.com\/questionnaire\/","user_agent":"Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko\/20100101 Firefox\/40.0","currency":"USD","created_by":1,"13.2":"","13.3":"Me","13.4":"","13.6":"McGee","13.8":"","14.2":"","14.3":"You","14.4":"","14.6":"McGoo","14.8":"","178":"CST","191":"","192":"","18.1":"","18.2":"","18.3":"","18.4":"","18.5":"","18.6":"United States","20.1":"","20.2":"","20.3":"","20.4":"","20.5":"","20.6":"United States","21.1":"","21.2":"","21.3":"","21.4":"","21.5":"","21.6":"United States","22.1":"","22.2":"","22.3":"","22.4":"","22.5":"","22.6":"United States","151":"","193":"","148.1":"","148.2":"","148.3":"","148.4":"","148.5":"","148.6":"","148.7":"","26":"","72":"","73":"","162":"","77":"","182":"","78":"","152":"","146.1":"","146.2":"","146.3":"","157":"","86":"","87":"","88":"","89":"","95":"","166":"","90":"","183":"","92":"","187":"","96":"","94":"","97":"","99":"","100":"","154":"","103":"","107":"","108":"","167":"","109":"","111":"","113":"","115":"","117":"","118":"","119":"","156":"","124":"","179":"","127":"","129":"","130":"","131":"","133":"","135":"","137":"","194":"","173":"","171":"","139":"","176":"50","197":"admin"},"field_values":"","page_number":"1","files":[],"gform_unique_id":"560319d874e94"}"; When it is unserialized, it appears like this: {"submitted_values":{"15":"","13":{"13.2":"","13.3":"Me","13.4":"","13.6":"McGee","13.8":""},"14":{"14.2":"","14.3":"You","14.4":"","14.6":"McGoo","14.8":""},"23":"","178":"CST","191":["","","pm"],"192":["","","pm"],"19":"","18":{"18.1":"","18.2":"","18.3":"","18.4":"","18.5":"","18.6":"United States","18_copy_values_activated":false},"20":{"20.1":"","20.2":"","20.3":"","20.4":"","20.5":"","20.6":"United States","20_copy_values_activated":true},"21":{"21.1":"","21.2":"","21.3":"","21.4":"","21.5":"","21.6":"United States","21_copy_values_activated":true},"22":{"22.1":"","22.2":"","22.3":"","22.4":"","22.5":"","22.6":"United States","22_copy_values_activated":true},"151":[{"Name":"","Position":"","Phone Number":"","Email":""}],"193":[""],"148":{"148.1":"","148.2":"","148.3":"","148.4":"","148.5":"","148.6":"","148.7":""},"149":[{"Name":"","Instrument":""}],"150":"","24":"","25":"","26":"","29":"","30":["","","pm"],"31":["","","pm"],"33":["","","pm"],"159":"","34":"","37":["","","am"],"39":"","40":"","32":"","41":"","42":"","170":["","","pm"],"43":"","180":"","44":"","46":"","62":"","160":"","50":"","47":"","48":"","51":"","52":"","53":"","54":"","55":"","181":"","56":"","57":"","141":"","142":"","58":"","59":"","60":"","61":"","196":"","63":"","64":"","65":"","67":"","66":"","161":{"161.1":"","161.2":"","161.3":""},"190":"","158":"","69":"","27":"","71":"","28":"","72":["","","pm"],"73":["","","pm"],"164":"","76":["","","pm"],"162":"","163":"","77":["","","pm"],"182":"","78":"","152":"","153":"","82":"","146":{"146.1":"","146.2":"","146.3":""},"157":"","79":"","83":"","84":"","85":"","86":["","","pm"],"87":["","","pm"],"88":["","","pm"],"89":"","95":[{"Name":"","Phonetic Spelling":"","Order":""}],"166":"","90":"","165":"","185":"","186":"","183":"","184":"","92":["","","pm"],"187":"","96":["","","pm"],"94":[{"Name":"","Relation":""}],"97":"","188":["","","pm"],"98":[{"Name":"","Phonetic Spelling":""}],"99":"","100":"","154":"","155":"","103":"","102":"","104":"","105":"","106":"","107":["","","pm"],"108":[{"Dancers":"","Relationship":"","Song\/Artist":"","Live\/DJ":""}],"167":"","168":"","109":"","110":"","111":"","112":"","113":"","114":"","115":"","169":"","116":[{"Song Title":"","Artist":"","Live\/DJ":""}],"117":"","118":"","119":"","120":"","156":"","147":"","121":"","122":"","123":"","124":"","189":"","179":"","126":"","127":"","128":["","","pm"],"129":["","","pm"],"130":["","","pm"],"131":"","132":"","133":"","134":[{"Wireless Name":"","Password":""}],"135":"","144":[{"College\/University Song":""}],"137":"","145":"","194":"","195":"","173":"","174":"","175":"","171":"","172":"","139":"","176":"50","197":"admin","198":null},"partial_entry":{"id":null,"post_id":null,"date_created":null,"form_id":4,"ip":"104.235.99.179","source_url":"example.com\/questionnaire\/","user_agent":"Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko\/20100101 Firefox\/40.0","currency":"USD","created_by":1,"13.2":"","13.3":"Me","13.4":"","13.6":"McGee","13.8":"","14.2":"","14.3":"You","14.4":"","14.6":"McGoo","14.8":"","178":"CST","191":"","192":"","18.1":"","18.2":"","18.3":"","18.4":"","18.5":"","18.6":"United States","20.1":"","20.2":"","20.3":"","20.4":"","20.5":"","20.6":"United States","21.1":"","21.2":"","21.3":"","21.4":"","21.5":"","21.6":"United States","22.1":"","22.2":"","22.3":"","22.4":"","22.5":"","22.6":"United States","151":"","193":"","148.1":"","148.2":"","148.3":"","148.4":"","148.5":"","148.6":"","148.7":"","26":"","72":"","73":"","162":"","77":"","182":"","78":"","152":"","146.1":"","146.2":"","146.3":"","157":"","86":"","87":"","88":"","89":"","95":"","166":"","90":"","183":"","92":"","187":"","96":"","94":"","97":"","99":"","100":"","154":"","103":"","107":"","108":"","167":"","109":"","111":"","113":"","115":"","117":"","118":"","119":"","156":"","124":"","179":"","127":"","129":"","130":"","131":"","133":"","135":"","137":"","194":"","173":"","171":"","139":"","176":"50","197":"admin"},"field_values":"","page_number":"1","files":[],"gform_unique_id":"560319d874e94"} Using json_decode, I get: object(stdClass)#615 (6) { ["submitted_values"]=> object(stdClass)#763 (164) { ["15"]=> string(0) "" ["13"]=> object(stdClass)#728 (5) { ["13.2"]=> string(0) "" ["13.3"]=> string(2) "Me" ["13.4"]=> string(0) "" ["13.6"]=> string(5) "McGee" ["13.8"]=> string(0) "" } ["14"]=> object(stdClass)#762 (5) { ["14.2"]=> string(0) "" ["14.3"]=> string(3) "You" ["14.4"]=> string(0) "" ["14.6"]=> string(5) "McGoo" ["14.8"]=> string(0) "" } ["23"]=> string(0) "" ["178"]=> string(3) "CST" ["191"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["192"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["19"]=> string(0) "" ["18"]=> object(stdClass)#761 (7) { ["18.1"]=> string(0) "" ["18.2"]=> string(0) "" ["18.3"]=> string(0) "" ["18.4"]=> string(0) "" ["18.5"]=> string(0) "" ["18.6"]=> string(13) "United States" ["18_copy_values_activated"]=> bool(false) } ["20"]=> object(stdClass)#760 (7) { ["20.1"]=> string(0) "" ["20.2"]=> string(0) "" ["20.3"]=> string(0) "" ["20.4"]=> string(0) "" ["20.5"]=> string(0) "" ["20.6"]=> string(13) "United States" ["20_copy_values_activated"]=> bool(true) } ["21"]=> object(stdClass)#759 (7) { ["21.1"]=> string(0) "" ["21.2"]=> string(0) "" ["21.3"]=> string(0) "" ["21.4"]=> string(0) "" ["21.5"]=> string(0) "" ["21.6"]=> string(13) "United States" ["21_copy_values_activated"]=> bool(true) } ["22"]=> object(stdClass)#758 (7) { ["22.1"]=> string(0) "" ["22.2"]=> string(0) "" ["22.3"]=> string(0) "" ["22.4"]=> string(0) "" ["22.5"]=> string(0) "" ["22.6"]=> string(13) "United States" ["22_copy_values_activated"]=> bool(true) } ["151"]=> array(1) { [0]=> object(stdClass)#757 (4) { ["Name"]=> string(0) "" ["Position"]=> string(0) "" ["Phone Number"]=> string(0) "" ["Email"]=> string(0) "" } } ["193"]=> array(1) { [0]=> string(0) "" } ["148"]=> object(stdClass)#756 (7) { ["148.1"]=> string(0) "" ["148.2"]=> string(0) "" ["148.3"]=> string(0) "" ["148.4"]=> string(0) "" ["148.5"]=> string(0) "" ["148.6"]=> string(0) "" ["148.7"]=> string(0) "" } ["149"]=> array(1) { [0]=> object(stdClass)#755 (2) { ["Name"]=> string(0) "" ["Instrument"]=> string(0) "" } } ["150"]=> string(0) "" ["24"]=> string(0) "" ["25"]=> string(0) "" ["26"]=> string(0) "" ["29"]=> string(0) "" ["30"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["31"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["33"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["159"]=> string(0) "" ["34"]=> string(0) "" ["37"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "am" } ["39"]=> string(0) "" ["40"]=> string(0) "" ["32"]=> string(0) "" ["41"]=> string(0) "" ["42"]=> string(0) "" ["170"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["43"]=> string(0) "" ["180"]=> string(0) "" ["44"]=> string(0) "" ["46"]=> string(0) "" ["62"]=> string(0) "" ["160"]=> string(0) "" ["50"]=> string(0) "" ["47"]=> string(0) "" ["48"]=> string(0) "" ["51"]=> string(0) "" ["52"]=> string(0) "" ["53"]=> string(0) "" ["54"]=> string(0) "" ["55"]=> string(0) "" ["181"]=> string(0) "" ["56"]=> string(0) "" ["57"]=> string(0) "" ["141"]=> string(0) "" ["142"]=> string(0) "" ["58"]=> string(0) "" ["59"]=> string(0) "" ["60"]=> string(0) "" ["61"]=> string(0) "" ["196"]=> string(0) "" ["63"]=> string(0) "" ["64"]=> string(0) "" ["65"]=> string(0) "" ["67"]=> string(0) "" ["66"]=> string(0) "" ["161"]=> object(stdClass)#754 (3) { ["161.1"]=> string(0) "" ["161.2"]=> string(0) "" ["161.3"]=> string(0) "" } ["190"]=> string(0) "" ["158"]=> string(0) "" ["69"]=> string(0) "" ["27"]=> string(0) "" ["71"]=> string(0) "" ["28"]=> string(0) "" ["72"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["73"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["164"]=> string(0) "" ["76"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["162"]=> string(0) "" ["163"]=> string(0) "" ["77"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["182"]=> string(0) "" ["78"]=> string(0) "" ["152"]=> string(0) "" ["153"]=> string(0) "" ["82"]=> string(0) "" ["146"]=> object(stdClass)#753 (3) { ["146.1"]=> string(0) "" ["146.2"]=> string(0) "" ["146.3"]=> string(0) "" } ["157"]=> string(0) "" ["79"]=> string(0) "" ["83"]=> string(0) "" ["84"]=> string(0) "" ["85"]=> string(0) "" ["86"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["87"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["88"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["89"]=> string(0) "" ["95"]=> array(1) { [0]=> object(stdClass)#694 (3) { ["Name"]=> string(0) "" ["Phonetic Spelling"]=> string(0) "" ["Order"]=> string(0) "" } } ["166"]=> string(0) "" ["90"]=> string(0) "" ["165"]=> string(0) "" ["185"]=> string(0) "" ["186"]=> string(0) "" ["183"]=> string(0) "" ["184"]=> string(0) "" ["92"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["187"]=> string(0) "" ["96"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["94"]=> array(1) { [0]=> object(stdClass)#697 (2) { ["Name"]=> string(0) "" ["Relation"]=> string(0) "" } } ["97"]=> string(0) "" ["188"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["98"]=> array(1) { [0]=> object(stdClass)#698 (2) { ["Name"]=> string(0) "" ["Phonetic Spelling"]=> string(0) "" } } ["99"]=> string(0) "" ["100"]=> string(0) "" ["154"]=> string(0) "" ["155"]=> string(0) "" ["103"]=> string(0) "" ["102"]=> string(0) "" ["104"]=> string(0) "" ["105"]=> string(0) "" ["106"]=> string(0) "" ["107"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["108"]=> array(1) { [0]=> object(stdClass)#699 (4) { ["Dancers"]=> string(0) "" ["Relationship"]=> string(0) "" ["Song/Artist"]=> string(0) "" ["Live/DJ"]=> string(0) "" } } ["167"]=> string(0) "" ["168"]=> string(0) "" ["109"]=> string(0) "" ["110"]=> string(0) "" ["111"]=> string(0) "" ["112"]=> string(0) "" ["113"]=> string(0) "" ["114"]=> string(0) "" ["115"]=> string(0) "" ["169"]=> string(0) "" ["116"]=> array(1) { [0]=> object(stdClass)#700 (3) { ["Song Title"]=> string(0) "" ["Artist"]=> string(0) "" ["Live/DJ"]=> string(0) "" } } ["117"]=> string(0) "" ["118"]=> string(0) "" ["119"]=> string(0) "" ["120"]=> string(0) "" ["156"]=> string(0) "" ["147"]=> string(0) "" ["121"]=> string(0) "" ["122"]=> string(0) "" ["123"]=> string(0) "" ["124"]=> string(0) "" ["189"]=> string(0) "" ["179"]=> string(0) "" ["126"]=> string(0) "" ["127"]=> string(0) "" ["128"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["129"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["130"]=> array(3) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(2) "pm" } ["131"]=> string(0) "" ["132"]=> string(0) "" ["133"]=> string(0) "" ["134"]=> array(1) { [0]=> object(stdClass)#701 (2) { ["Wireless Name"]=> string(0) "" ["Password"]=> string(0) "" } } ["135"]=> string(0) "" ["144"]=> array(1) { [0]=> object(stdClass)#702 (1) { ["College/University Song"]=> string(0) "" } } ["137"]=> string(0) "" ["145"]=> string(0) "" ["194"]=> string(0) "" ["195"]=> string(0) "" ["173"]=> string(0) "" ["174"]=> string(0) "" ["175"]=> string(0) "" ["171"]=> string(0) "" ["172"]=> string(0) "" ["139"]=> string(0) "" ["176"]=> string(2) "50" ["197"]=> string(5) "admin" ["198"]=> NULL } ["partial_entry"]=> object(stdClass)#703 (110) { ["id"]=> NULL ["post_id"]=> NULL ["date_created"]=> NULL ["form_id"]=> int(4) ["ip"]=> string(14) "104.235.99.179" ["source_url"]=> string(53) "example.com/questionnaire/" ["user_agent"]=> string(72) "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0" ["currency"]=> string(3) "USD" ["created_by"]=> int(1) ["13.2"]=> string(0) "" ["13.3"]=> string(2) "Me" ["13.4"]=> string(0) "" ["13.6"]=> string(5) "McGee" ["13.8"]=> string(0) "" ["14.2"]=> string(0) "" ["14.3"]=> string(3) "You" ["14.4"]=> string(0) "" ["14.6"]=> string(5) "McGoo" ["14.8"]=> string(0) "" ["178"]=> string(3) "CST" ["191"]=> string(0) "" ["192"]=> string(0) "" ["18.1"]=> string(0) "" ["18.2"]=> string(0) "" ["18.3"]=> string(0) "" ["18.4"]=> string(0) "" ["18.5"]=> string(0) "" ["18.6"]=> string(13) "United States" ["20.1"]=> string(0) "" ["20.2"]=> string(0) "" ["20.3"]=> string(0) "" ["20.4"]=> string(0) "" ["20.5"]=> string(0) "" ["20.6"]=> string(13) "United States" ["21.1"]=> string(0) "" ["21.2"]=> string(0) "" ["21.3"]=> string(0) "" ["21.4"]=> string(0) "" ["21.5"]=> string(0) "" ["21.6"]=> string(13) "United States" ["22.1"]=> string(0) "" ["22.2"]=> string(0) "" ["22.3"]=> string(0) "" ["22.4"]=> string(0) "" ["22.5"]=> string(0) "" ["22.6"]=> string(13) "United States" ["151"]=> string(0) "" ["193"]=> string(0) "" ["148.1"]=> string(0) "" ["148.2"]=> string(0) "" ["148.3"]=> string(0) "" ["148.4"]=> string(0) "" ["148.5"]=> string(0) "" ["148.6"]=> string(0) "" ["148.7"]=> string(0) "" ["26"]=> string(0) "" ["72"]=> string(0) "" ["73"]=> string(0) "" ["162"]=> string(0) "" ["77"]=> string(0) "" ["182"]=> string(0) "" ["78"]=> string(0) "" ["152"]=> string(0) "" ["146.1"]=> string(0) "" ["146.2"]=> string(0) "" ["146.3"]=> string(0) "" ["157"]=> string(0) "" ["86"]=> string(0) "" ["87"]=> string(0) "" ["88"]=> string(0) "" ["89"]=> string(0) "" ["95"]=> string(0) "" ["166"]=> string(0) "" ["90"]=> string(0) "" ["183"]=> string(0) "" ["92"]=> string(0) "" ["187"]=> string(0) "" ["96"]=> string(0) "" ["94"]=> string(0) "" ["97"]=> string(0) "" ["99"]=> string(0) "" ["100"]=> string(0) "" ["154"]=> string(0) "" ["103"]=> string(0) "" ["107"]=> string(0) "" ["108"]=> string(0) "" ["167"]=> string(0) "" ["109"]=> string(0) "" ["111"]=> string(0) "" ["113"]=> string(0) "" ["115"]=> string(0) "" ["117"]=> string(0) "" ["118"]=> string(0) "" ["119"]=> string(0) "" ["156"]=> string(0) "" ["124"]=> string(0) "" ["179"]=> string(0) "" ["127"]=> string(0) "" ["129"]=> string(0) "" ["130"]=> string(0) "" ["131"]=> string(0) "" ["133"]=> string(0) "" ["135"]=> string(0) "" ["137"]=> string(0) "" ["194"]=> string(0) "" ["173"]=> string(0) "" ["171"]=> string(0) "" ["139"]=> string(0) "" ["176"]=> string(2) "50" ["197"]=> string(5) "admin" } ["field_values"]=> string(0) "" ["page_number"]=> string(1) "1" ["files"]=> array(0) { } ["gform_unique_id"]=> string(13) "560319d874e94" } bool(true) I want to be able to grab the values for 13.3, 13.6 and 14.3, 14.6. Those are always the first and last names. What do I need to do in php to grab just those particular values? I tried print $content->{'14.6'}; $content being the name of the string I used for the output.
You can try this: $str = '{"submitted_values":{"15":"","13":{"13.2":"","13.3":"Me","13.4":"","13.6":"McGee","13.8":""},"14":{"14.2":"","14.3":"You","14.4":"","14.6":"McGoo","14.8":""},"23":"","178":"CST","191":["","","pm"],"192":["","","pm"],"19":"","18":{"18.1":"","18.2":"","18.3":"","18.4":"","18.5":"","18.6":"United States","18_copy_values_activated":false},"20":{"20.1":"","20.2":"","20.3":"","20.4":"","20.5":"","20.6":"United States","20_copy_values_activated":true},"21":{"21.1":"","21.2":"","21.3":"","21.4":"","21.5":"","21.6":"United States","21_copy_values_activated":true},"22":{"22.1":"","22.2":"","22.3":"","22.4":"","22.5":"","22.6":"United States","22_copy_values_activated":true},"151":[{"Name":"","Position":"","Phone Number":"","Email":""}],"193":[""],"148":{"148.1":"","148.2":"","148.3":"","148.4":"","148.5":"","148.6":"","148.7":""},"149":[{"Name":"","Instrument":""}],"150":"","24":"","25":"","26":"","29":"","30":["","","pm"],"31":["","","pm"],"33":["","","pm"],"159":"","34":"","37":["","","am"],"39":"","40":"","32":"","41":"","42":"","170":["","","pm"],"43":"","180":"","44":"","46":"","62":"","160":"","50":"","47":"","48":"","51":"","52":"","53":"","54":"","55":"","181":"","56":"","57":"","141":"","142":"","58":"","59":"","60":"","61":"","196":"","63":"","64":"","65":"","67":"","66":"","161":{"161.1":"","161.2":"","161.3":""},"190":"","158":"","69":"","27":"","71":"","28":"","72":["","","pm"],"73":["","","pm"],"164":"","76":["","","pm"],"162":"","163":"","77":["","","pm"],"182":"","78":"","152":"","153":"","82":"","146":{"146.1":"","146.2":"","146.3":""},"157":"","79":"","83":"","84":"","85":"","86":["","","pm"],"87":["","","pm"],"88":["","","pm"],"89":"","95":[{"Name":"","Phonetic Spelling":"","Order":""}],"166":"","90":"","165":"","185":"","186":"","183":"","184":"","92":["","","pm"],"187":"","96":["","","pm"],"94":[{"Name":"","Relation":""}],"97":"","188":["","","pm"],"98":[{"Name":"","Phonetic Spelling":""}],"99":"","100":"","154":"","155":"","103":"","102":"","104":"","105":"","106":"","107":["","","pm"],"108":[{"Dancers":"","Relationship":"","Song\/Artist":"","Live\/DJ":""}],"167":"","168":"","109":"","110":"","111":"","112":"","113":"","114":"","115":"","169":"","116":[{"Song Title":"","Artist":"","Live\/DJ":""}],"117":"","118":"","119":"","120":"","156":"","147":"","121":"","122":"","123":"","124":"","189":"","179":"","126":"","127":"","128":["","","pm"],"129":["","","pm"],"130":["","","pm"],"131":"","132":"","133":"","134":[{"Wireless Name":"","Password":""}],"135":"","144":[{"College\/University Song":""}],"137":"","145":"","194":"","195":"","173":"","174":"","175":"","171":"","172":"","139":"","176":"50","197":"admin","198":null},"partial_entry":{"id":null,"post_id":null,"date_created":null,"form_id":4,"ip":"104.235.99.179","source_url":"http:\/\/www.mysite.com\/questionnaire\/","user_agent":"Mozilla\/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko\/20100101 Firefox\/40.0","currency":"USD","created_by":1,"13.2":"","13.3":"Me","13.4":"","13.6":"McGee","13.8":"","14.2":"","14.3":"You","14.4":"","14.6":"McGoo","14.8":"","178":"CST","191":"","192":"","18.1":"","18.2":"","18.3":"","18.4":"","18.5":"","18.6":"United States","20.1":"","20.2":"","20.3":"","20.4":"","20.5":"","20.6":"United States","21.1":"","21.2":"","21.3":"","21.4":"","21.5":"","21.6":"United States","22.1":"","22.2":"","22.3":"","22.4":"","22.5":"","22.6":"United States","151":"","193":"","148.1":"","148.2":"","148.3":"","148.4":"","148.5":"","148.6":"","148.7":"","26":"","72":"","73":"","162":"","77":"","182":"","78":"","152":"","146.1":"","146.2":"","146.3":"","157":"","86":"","87":"","88":"","89":"","95":"","166":"","90":"","183":"","92":"","187":"","96":"","94":"","97":"","99":"","100":"","154":"","103":"","107":"","108":"","167":"","109":"","111":"","113":"","115":"","117":"","118":"","119":"","156":"","124":"","179":"","127":"","129":"","130":"","131":"","133":"","135":"","137":"","194":"","173":"","171":"","139":"","176":"50","197":"admin"},"field_values":"","page_number":"1","files":[],"gform_unique_id":"560319d874e94"}'; $obj = json_decode($str); echo $fullname1 = $obj->submitted_values->{'13'}->{'13.3'} . ' ' . $obj->submitted_values->{'13'}->{'13.6'}; echo $fullname2 = $obj->submitted_values->{'14'}->{'14.3'} . ' ' . $obj->submitted_values->{'14'}->{'14.6'};
Retrieve values from view in PHP module development
I have retrieve a view programmaticly in my module with PHP. How can retrieve the values of this view? I'm using drupal 6. That's the view result in my PHP code: enter code hereobject(view)#48 (22) { ["db_table"]=> string(10) "views_view" ["base_table"]=> string(4) "node" ["args"]=> array(0) { } ["use_ajax"]=> bool(false) ["result"]=> array(0) { } ["pager"]=> array(5) { ["use_pager"]=> bool(false) ["items_per_page"]=> int(10) ["element"]=> int(0) ["offset"]=> int(0) ["current_page"]=> int(0) } ["old_view"]=> array(0) { } ["vid"]=> string(2) "48" ["name"]=> string(7) "student" ["description"]=> string(7) "Student" ["tag"]=> string(0) "" ["view_php"]=> string(0) "" ["is_cacheable"]=> string(1) "0" ["display"]=> array(2) { ["default"]=> object(views_display)#11 (7) { ["db_table"]=> string(13) "views_display" ["vid"]=> string(2) "48" ["id"]=> string(7) "default" ["display_title"]=> string(8) "Defaults" ["display_plugin"]=> string(7) "default" ["position"]=> string(1) "1" ["display_options"]=> array(2) { ["fields"]=> array(5) { ["field_locatie_student_lid"]=> array(14) { ["label"]=> string(7) "Locatie" ["alter"]=> array(16) { ["alter_text"]=> int(0) ["text"]=> string(0) "" ["make_link"]=> int(0) ["path"]=> string(0) "" ["link_class"]=> string(0) "" ["alt"]=> string(0) "" ["prefix"]=> string(0) "" ["suffix"]=> string(0) "" ["target"]=> string(0) "" ["help"]=> string(0) "" ["trim"]=> int(0) ["max_length"]=> string(0) "" ["word_boundary"]=> int(1) ["ellipsis"]=> int(1) ["html"]=> int(0) ["strip_tags"]=> int(0) } ["empty"]=> string(41) "geen overeenkomstige resultaten gevonden." ["hide_empty"]=> int(0) ["empty_zero"]=> int(0) ["link_to_node"]=> int(0) ["label_type"]=> string(6) "widget" ["format"]=> string(7) "default" ["multiple"]=> array(4) { ["group"]=> bool(true) ["multiple_number"]=> string(0) "" ["multiple_from"]=> string(0) "" ["multiple_reversed"]=> bool(false) } ["exclude"]=> int(0) ["id"]=> string(25) "field_locatie_student_lid" ["table"]=> string(31) "node_data_field_locatie_student" ["field"]=> string(25) "field_locatie_student_lid" ["relationship"]=> string(4) "none" } ["field_naam_student_value"]=> array(14) { ["label"]=> string(4) "Naam" ["alter"]=> array(16) { ["alter_text"]=> int(0) ["text"]=> string(0) "" ["make_link"]=> int(0) ["path"]=> string(0) "" ["link_class"]=> string(0) "" ["alt"]=> string(0) "" ["prefix"]=> string(0) "" ["suffix"]=> string(0) "" ["target"]=> string(0) "" ["help"]=> string(0) "" ["trim"]=> int(0) ["max_length"]=> string(0) "" ["word_boundary"]=> int(1) ["ellipsis"]=> int(1) ["html"]=> int(0) ["strip_tags"]=> int(0) } ["empty"]=> string(41) "geen overeenkomstige resultaten gevonden." ["hide_empty"]=> int(0) ["empty_zero"]=> int(0) ["link_to_node"]=> int(0) ["label_type"]=> string(6) "widget" ["format"]=> string(7) "default" ["multiple"]=> array(4) { ["group"]=> bool(true) ["multiple_number"]=> string(0) "" ["multiple_from"]=> string(0) "" ["multiple_reversed"]=> bool(false) } ["exclude"]=> int(0) ["id"]=> string(24) "field_naam_student_value" ["table"]=> string(28) "node_data_field_naam_student" ["field"]=> string(24) "field_naam_student_value" ["relationship"]=> string(4) "none" } ["field_ugentid_student_value"]=> array(14) { ["label"]=> string(7) "UGentID" ["alter"]=> array(16) { ["alter_text"]=> int(0) ["text"]=> string(0) "" ["make_link"]=> int(0) ["path"]=> string(0) "" ["link_class"]=> string(0) "" ["alt"]=> string(0) "" ["prefix"]=> string(0) "" ["suffix"]=> string(0) "" ["target"]=> string(0) "" ["help"]=> string(0) "" ["trim"]=> int(0) ["max_length"]=> string(0) "" ["word_boundary"]=> int(1) ["ellipsis"]=> int(1) ["html"]=> int(0) ["strip_tags"]=> int(0) } ["empty"]=> string(41) "geen overeenkomstige resultaten gevonden." ["hide_empty"]=> int(0) ["empty_zero"]=> int(0) ["link_to_node"]=> int(0) ["label_type"]=> string(6) "widget" ["format"]=> string(7) "default" ["multiple"]=> array(4) { ["group"]=> bool(true) ["multiple_number"]=> string(0) "" ["multiple_from"]=> string(0) "" ["multiple_reversed"]=> bool(false) } ["exclude"]=> int(0) ["id"]=> string(27) "field_ugentid_student_value" ["table"]=> string(31) "node_data_field_ugentid_student" ["field"]=> string(27) "field_ugentid_student_value" ["relationship"]=> string(4) "none" } ["field_voornaam_student_value"]=> array(14) { ["label"]=> string(8) "Voornaam" ["alter"]=> array(16) { ["alter_text"]=> int(0) ["text"]=> string(0) "" ["make_link"]=> int(0) ["path"]=> string(0) "" ["link_class"]=> string(0) "" ["alt"]=> string(0) "" ["prefix"]=> string(0) "" ["suffix"]=> string(0) "" ["target"]=> string(0) "" ["help"]=> string(0) "" ["trim"]=> int(0) ["max_length"]=> string(0) "" ["word_boundary"]=> int(1) ["ellipsis"]=> int(1) ["html"]=> int(0) ["strip_tags"]=> int(0) } ["empty"]=> string(41) "geen overeenkomstige resultaten gevonden." ["hide_empty"]=> int(0) ["empty_zero"]=> int(0) ["link_to_node"]=> int(0) ["label_type"]=> string(6) "widget" ["format"]=> string(7) "default" ["multiple"]=> array(4) { ["group"]=> bool(true) ["multiple_number"]=> string(0) "" ["multiple_from"]=> string(0) "" ["multiple_reversed"]=> bool(false) } ["exclude"]=> int(0) ["id"]=> string(28) "field_voornaam_student_value" ["table"]=> string(32) "node_data_field_voornaam_student" ["field"]=> string(28) "field_voornaam_student_value" ["relationship"]=> string(4) "none" } ["field_voorkeur_student_value"]=> array(14) { ["label"]=> string(19) "Voorkeurstageplaats" ["alter"]=> array(16) { ["alter_text"]=> int(0) ["text"]=> string(0) "" ["make_link"]=> int(0) ["path"]=> string(0) "" ["link_class"]=> string(0) "" ["alt"]=> string(0) "" ["prefix"]=> string(0) "" ["suffix"]=> string(0) "" ["target"]=> string(0) "" ["help"]=> string(0) "" ["trim"]=> int(0) ["max_length"]=> string(0) "" ["word_boundary"]=> int(1) ["ellipsis"]=> int(1) ["html"]=> int(0) ["strip_tags"]=> int(0) } ["empty"]=> string(41) "geen overeenkomstige resultaten gevonden." ["hide_empty"]=> int(0) ["empty_zero"]=> int(0) ["link_to_node"]=> int(0) ["label_type"]=> string(6) "widget" ["format"]=> string(7) "default" ["multiple"]=> array(4) { ["group"]=> bool(true) ["multiple_number"]=> string(0) "" ["multiple_from"]=> string(0) "" ["multiple_reversed"]=> bool(false) } ["exclude"]=> int(0) ["id"]=> string(28) "field_voorkeur_student_value" ["table"]=> string(32) "node_data_field_voorkeur_student" ["field"]=> string(28) "field_voorkeur_student_value" ["relationship"]=> string(4) "none" } } ["filters"]=> array(2) { ["type"]=> array(9) { ["operator"]=> string(2) "in" ["value"]=> array(1) { ["student"]=> string(7) "student" } ["group"]=> string(1) "0" ["exposed"]=> bool(false) ["expose"]=> array(2) { ["operator"]=> bool(false) ["label"]=> string(0) "" } ["id"]=> string(4) "type" ["table"]=> string(4) "node" ["field"]=> string(4) "type" ["relationship"]=> string(4) "none" } ["field_ugentid_student_value"]=> array(9) { ["operator"]=> string(9) "not empty" ["value"]=> array(3) { ["value"]=> string(0) "" ["min"]=> string(0) "" ["max"]=> string(0) "" } ["group"]=> string(1) "0" ["exposed"]=> bool(false) ["expose"]=> array(2) { ["operator"]=> bool(false) ["label"]=> string(0) "" } ["id"]=> string(27) "field_ugentid_student_value" ["table"]=> string(31) "node_data_field_ugentid_student" ["field"]=> string(27) "field_ugentid_student_value" ["relationship"]=> string(4) "none" } } } } ["page_1"]=> object(views_display)#43 (7) { ["db_table"]=> string(13) "views_display" ["vid"]=> string(2) "48" ["id"]=> string(6) "page_1" ["display_title"]=> string(6) "Pagina" ["display_plugin"]=> string(4) "page" ["position"]=> string(1) "2" ["display_options"]=> array(1) { ["path"]=> string(17) "studentenLijstCSV" } } } ["type"]=> string(6) "Normal" ["loaded"]=> bool(true) ["executed"]=> bool(false) ["built"]=> bool(false) ["build_info"]=> array(0) { } ["attachment_before"]=> string(0) "" ["attachment_after"]=> string(0) "" ["get_total_rows"]=> bool(true) } <div style="display: none" id="drupalforfirebug_general"><fieldset><legend>Drupal for Firebug General Messages</legend>There were no messages sent to the general log. Please use "firep($item, $optional_title)" to output messages to this console.</div><div style="display: none" id="drupalforfirebug_sql"><fieldset><legend>Devel Module is Not Installed</legend>Please install and enable the Devel Module to display the SQL queries.</fieldset></div><div style="display: none" id="drupalforfirebug_hook_form_alter">There was no form altering.</div><div style="display: none" id="drupalforfirebug_hook_user">There was no user processing.</div><div style="display: none" id="drupalforfirebug_hook_nodeapi">There was no node processing.</div><div style="display: none" id="drupalforfirebug_hook_views">There was no views processing.</div><div style="display: none" id="drupalforfirebug_php"><object style="width:100%;frameborder=0;height=100%;margin-bottom:-3px;" type="text/html" data="http://localhost/testplanning/?q=admin/firebug/exec"></object></div><div style="display: none" id="drupalforfirebug_hook_page_alter">This feature is only available in Drupal 7.</div>
why you not using just views? $view = view_get_view('MY_VIEW_NAME'); $view->set_display('MY_DISPLAY'); // page_1 or block_1 ... block_n, ...page_n $view->set_items_per_page(0); $view->execute(); $result = $view->result; $result will contains array of values of each row
I haven't actually tried this myself. First thing to do would be to execute the views query. This can be done with the execute function. So doing something like this: $view->execute('display_id'); Should populate the $view object with at least some data. The data available differs through the different layers of theme functions, so you might not get what you want. But this is the best method I can think of.
Sort object as value with int and text value
I have a object and have a problem, this object here $product have this keys ( product_title, product_price, product_stock ) and more, I need to sort after product_title and if my object have this products in I can't sort it right. test product 1 test product 11 test product 111 test product 2 test product 20 test product 3 test product 33 test product 333 The right way to sort it its like this: test product 1 test product 2 test product 3 test product 11 test product 33 test product 20 test product 111 test product 333 I have tried sort and rsort without luck. If it can help, my object looks like this: array(8) { [0]=> object(stdClass)#12 (49) { ["product_id"]=> string(3) "335" ["product_guid"]=> string(36) "F0161D03-33EF-6F40-C816-AEDB33640E36" ["account_id"]=> string(2) "28" ["category_id"]=> string(3) "189" ["brand_guid"]=> NULL ["product_title"]=> string(10) "Fadestativ" ["push_date"]=> string(19) "2011-01-18 13:02:11" ["product_price"]=> string(3) "560" ["product_price_before"]=> string(1) "0" ["on_stock"]=> string(1) "0" ["product_weight"]=> string(1) "0" ["product_int_number"]=> string(0) "" ["product_ext_number"]=> string(0) "" ["product_small_info"]=> string(0) "" ["product_big_info"]=> string(31) "3 benet fad stativ højde 19 cm" ["active"]=> string(1) "1" ["meta_title"]=> string(0) "" ["meta_keyword"]=> string(0) "" ["meta_description"]=> string(0) "" ["product_new"]=> string(1) "0" ["indicative_price"]=> string(1) "0" ["cost_price"]=> string(1) "0" ["id"]=> string(2) "28" ["domain"]=> string(26) "eventhuset.schemecloud.com" ["password"]=> string(32) "098f6bcd4621d373cade4e832627b4f6" ["resellerid"]=> string(1) "2" ["defualt_lang"]=> string(2) "dk" ["quota"]=> string(3) "100" ["account_type"]=> string(3) "cms" ["busniess_name"]=> string(0) "" ["busniess_street"]=> string(0) "" ["busniess_city"]=> string(0) "" ["busniess_zipcode"]=> string(0) "" ["busniess_contry"]=> string(0) "" ["busniess_phone"]=> string(0) "" ["busniess_contact_person"]=> string(0) "" ["busniess_contact_phone"]=> string(0) "" ["busniess_email"]=> string(0) "" ["busniess_cvr"]=> string(0) "" ["invoice_name"]=> string(0) "" ["invoice_street"]=> string(0) "" ["invoice_city"]=> string(0) "" ["invoice_zipcode"]=> string(0) "" ["invoice_contry"]=> string(0) "" ["invoice_contact_person"]=> string(0) "" ["invoice_cvr"]=> string(0) "" ["payment_expires"]=> string(19) "0000-00-00 00:00:00" ["next_order_number"]=> string(5) "10001" ["order_prefix"]=> string(0) "" } [1]=> object(stdClass)#14 (49) { ["product_id"]=> string(3) "306" ["product_guid"]=> string(36) "8119C253-84C7-73AC-4125-DF4B1728A203" ["account_id"]=> string(2) "28" ["category_id"]=> string(3) "189" ["brand_guid"]=> NULL ["product_title"]=> string(15) "Kartoffel skål" ["push_date"]=> string(19) "2011-01-17 13:40:08" ["product_price"]=> string(3) "680" ["product_price_before"]=> string(1) "0" ["on_stock"]=> string(1) "0" ["product_weight"]=> string(1) "0" ["product_int_number"]=> string(0) "" ["product_ext_number"]=> string(0) "" ["product_small_info"]=> string(0) "" ["product_big_info"]=> string(31) "Kartoffel skål i rustfri stål" ["active"]=> string(1) "1" ["meta_title"]=> string(0) "" ["meta_keyword"]=> string(0) "" ["meta_description"]=> string(0) "" ["product_new"]=> string(1) "0" ["indicative_price"]=> string(1) "0" ["cost_price"]=> string(1) "0" ["id"]=> string(2) "28" ["domain"]=> string(26) "eventhuset.schemecloud.com" ["password"]=> string(32) "098f6bcd4621d373cade4e832627b4f6" ["resellerid"]=> string(1) "2" ["defualt_lang"]=> string(2) "dk" ["quota"]=> string(3) "100" ["account_type"]=> string(3) "cms" ["busniess_name"]=> string(0) "" ["busniess_street"]=> string(0) "" ["busniess_city"]=> string(0) "" ["busniess_zipcode"]=> string(0) "" ["busniess_contry"]=> string(0) "" ["busniess_phone"]=> string(0) "" ["busniess_contact_person"]=> string(0) "" ["busniess_contact_phone"]=> string(0) "" ["busniess_email"]=> string(0) "" ["busniess_cvr"]=> string(0) "" ["invoice_name"]=> string(0) "" ["invoice_street"]=> string(0) "" ["invoice_city"]=> string(0) "" ["invoice_zipcode"]=> string(0) "" ["invoice_contry"]=> string(0) "" ["invoice_contact_person"]=> string(0) "" ["invoice_cvr"]=> string(0) "" ["payment_expires"]=> string(19) "0000-00-00 00:00:00" ["next_order_number"]=> string(5) "10001" ["order_prefix"]=> string(0) "" } and I need to sort after array(8) { [0]=> object(stdClass)#12 (49) { ["product_title"]=> string(10) "Fadestativ" }
Well, assuming that they are objects (which from your description and comments they appear to be), you can use a usort. PHP 5.3+: usort( $array, function($a, $b) { return strnatcmp($a->title, $b->title); } ); PHP <= 5.2: usort( $array; create_function('$a, $b', 'return strnatcmp($a->title, $b->title);`) ); Change ->title to whatever property you want to sort by. And if you want case insensitivity, use strnatcasecmp instead of strnatcmp()...
Try sort() again but you will have to use a second parameter: sort($array, SORT_STRING);