In this array, I am attempting to extract the value int(2128) from the ["member_count"] key.
array(3) {
["total"]=>
int(1)
["data"]=>
array(1) {
[0]=>
array(17) {
["id"]=>
string(10) "999999999999"
["web_id"]=>
int(421097)
["name"]=>
string(21) "Name Of List"
["date_created"]=>
string(19) "2014-07-14 13:51:01"
["email_type_option"]=>
bool(false)
["use_awesomebar"]=>
bool(true)
["default_from_name"]=>
string(14) "Department Name"
["default_from_email"]=>
string(24) "user#email.com"
["default_subject"]=>
string(0) ""
["default_language"]=>
string(2) "en"
["list_rating"]=>
float(3.5)
["subscribe_url_short"]=>
string(23) "website/4545"
["subscribe_url_long"]=>
string(91) "website"
["beamer_address"]=>
string(47) "key goes here"
["visibility"]=>
string(3) "pub"
["stats"]=>
array(16) {
["member_count"]=>
int(2128)
["unsubscribe_count"]=>
int(20)
["cleaned_count"]=>
int(57)
["member_count_since_send"]=>
int(1)
["unsubscribe_count_since_send"]=>
int(9)
["cleaned_count_since_send"]=>
int(29)
["campaign_count"]=>
int(2)
["grouping_count"]=>
int(1)
["group_count"]=>
int(4)
["merge_var_count"]=>
int(6)
["avg_sub_rate"]=>
int(17)
["avg_unsub_rate"]=>
int(3)
["target_sub_rate"]=>
int(17)
["open_rate"]=>
float(38.672399892502)
["click_rate"]=>
float(14.932747735383)
["date_last_campaign"]=>
string(19) "2014-11-07 19:14:30"
}
["modules"]=>
array(0) {
}
}
}
["errors"]=>
array(0) {
}
}
Here is the PHP that I have so far but I'm unable to get just the value "int(2128)"
foreach($result as $row){
foreach($row[0] as $row1){
echo '<pre>';
var_dump($row1['member_count']);
echo '</pre>';
}
}
The Results I get:
string(1) "6"
NULL
string(1) "F"
string(1) "2"
NULL
NULL
string(1) "B"
string(1) "d"
string(0) ""
string(1) "e"
NULL
string(1) "h"
string(1) "h"
string(1) "u"
string(1) "p"
int(2128)
NULL
I greatly appreciate any help to narrow the results down to just the value "int(2128)".
Thanks.
If you only want the value 2128 use this:
$array['data'][0]['stats']['member_count']
($array is the name of your multidimensional array)
Related
I have small problem, I can't get info from an array.
This is outcome when I var_dump variable.
array(1) {
["server"]=> array(34) {
["dedicated"]=> string(1) "d"
["game_descr"]=> string(14) "Counter-Strike"
["game_dir"]=> string(7) "cstrike"
["gq_address"]=> string(13) "185.119.89.91"
["gq_dedicated"]=> string(1) "d"
["gq_gametype"]=> string(14) "Counter-Strike"
["gq_hostname"]=> string(26) "Assassin'S CSDM [de_dust2]"
["gq_joinlink"]=> string(36) "steam://connect/185.119.89.91:27031/"
["gq_mapname"]=> string(8) "de_dust2"
["gq_maxplayers"]=> int(32)
["gq_mod"]=> string(7) "cstrike"
["gq_name"]=> string(18) "Counter-Strike 1.6"
["gq_numplayers"]=> int(32)
["gq_online"]=> bool(true)
["gq_password"]=> int(0)
["gq_port_client"]=> int(27031)
["gq_port_query"]=> int(27031)
["gq_protocol"]=> string(6) "source"
["gq_transport"]=> string(3) "udp"
["gq_type"]=> string(4) "cs16"
["hostname"]=> string(26) "Assassin'S CSDM [de_dust2]"
["map"]=> string(8) "de_dust2"
["max_players"]=> int(32)
["num_bots"]=> int(0)
["num_players"]=> int(32)
["os"]=> string(1) "l"
["password"]=> int(0)
["players"]=> array(0) { }
["port"]=> int(27031)
["protocol"]=> int(48)
["secure"]=> int(1)
["steamappid"]=> int(10)
["teams"]=> array(0) { }
["version"]=> string(13) "1.1.2.7/Stdio"
}
}
How to get hostname for example?
I tried like $info['hostname'], $info[0]['hostname']; But nothing works, why?
array(1) { ... }
The array has one thing in it.
["server"]=> array(34) { ... }
… which is another array with 34 things in it.
You are ignoring the outer array. You need to get the inner array and then access the item you want from that.
$info['server']['hostname']
I'm using cakephp 2.x and I would like to get certain element as field from my model. the problem is with my structure. If I use find all then I recieve this:
array(9) {
[0]=> ...
[1]=>
array(7) {
["Person"]=>
array(18) {
["id"]=>
int(2)
["imie"]=>
string(6) "STEFAN"
["nazwisko"]=>
string(8) "ŚMIAŁY"
["tel"]=>
string(13) "+55 648989748"
["mob"]=>
string(13) "+87 489747489"
["email"]=>
string(25) "HSDJKAHSDJK#HSDFJASHF.CIJ"
["tytul_naukowy"]=>
string(7) "TEZ NIE"
["data_od"]=>
string(10) "2017-02-16"
["data_do"]=>
NULL
["object_id"]=>
int(-1)
["object_type_id"]=>
int(2)
["duty_id"]=>
int(28)
["created"]=>
string(22) "2017-02-16 13:22:32+01"
["modified"]=>
string(22) "2017-02-16 13:22:32+01"
["deleted"]=>
int(0)
["additional_email"]=>
string(17) "UDIHAS#HFSDKFH.OK"
["description"]=>
string(4) "OPIS"
["displayName"]=>
string(15) "STEFAN ŚMIAŁY"
}
["Duty"]=>
array(3) {
["id"]=>
int(28)
["nazwa"]=>
string(20) "KOORDYNATOR RECEPCJI"
["atrybut"]=>
string(1) "W"
}
["ObjectType"]=>
array(3) {
["id"]=>
int(2)
["nazwa"]=>
string(4) "Obks"
["model"]=>
string(3) "Obk"
}
["Cro"]=>
array(12) {
["id"]=>
NULL
["created"]=>
NULL
["nazwa"]=>
NULL
["tel"]=>
NULL
["fax"]=>
NULL
["email"]=>
NULL
["www"]=>
NULL
["modified"]=>
NULL
["deleted"]=>
NULL
["cro_type_id"]=>
NULL
["displayName"]=>
NULL
["objectTypeIdWithId"]=>
NULL
}
["Attachment"]=>
array(0) {
}
["Specialization"]=>
array(0) {
}
["Obk"]=>
array(1) {
[0]=>
array(13) {
["id"]=>
int(2)
["nazwa"]=>
string(10) "OBK Z ID 2"
["tel"]=>
string(13) "+48 123456890"
["fax"]=>
string(13) "+48 123456789"
["email"]=>
string(15) "EMAIL#EMAIL.COM"
["www"]=>
string(11) "WWW.WWW.WWW"
["modified"]=>
string(22) "2017-03-20 15:11:31+01"
["created"]=>
string(22) "2014-05-12 21:50:17+02"
["deleted"]=>
int(0)
["local_order"]=>
int(3)
["displayName"]=>
string(10) "OBK Z ID 2"
["objectTypeIdWithId"]=>
string(3) "2_2"
["PeopleObk"]=>
array(3) {
["id"]=>
int(1)
["person_id"]=>
int(2)
["obk_id"]=>
int(2)
}
}
}
}
[2]=>
array(7) {
["Person"]=>
array(18) {
["id"]=>
int(3)
["imie"]=>
string(5) "KAMIL"
["nazwisko"]=>
string(10) "STEFAŃSKI"
["tel"]=>
string(13) "+23 123123123"
["mob"]=>
string(13) "+21 412312312"
["email"]=>
string(16) "ASDASD#SDFDSF.LS"
["tytul_naukowy"]=>
string(3) "NIE"
["data_od"]=>
string(10) "2017-02-22"
["data_do"]=>
NULL
["object_id"]=>
int(-1)
["object_type_id"]=>
int(2)
["duty_id"]=>
int(26)
["created"]=>
string(22) "2017-02-22 16:14:32+01"
["modified"]=>
string(22) "2017-02-22 16:14:32+01"
["deleted"]=>
int(0)
["additional_email"]=>
string(22) "ADAM.2313#WEBIMPULS.PL"
["description"]=>
string(4) "TEST"
["displayName"]=>
string(16) "KAMIL STEFAŃSKI"
}
["Duty"]=>
array(3) {
["id"]=>
int(26)
["nazwa"]=>
string(41) "KOORDYNATOR OŚRODKÓW BADAŃ KLINICZNYCH"
["atrybut"]=>
string(1) "W"
}
["ObjectType"]=>
array(3) {
["id"]=>
int(2)
["nazwa"]=>
string(4) "Obks"
["model"]=>
string(3) "Obk"
}
["Cro"]=>
array(12) {
["id"]=>
NULL
["created"]=>
NULL
["nazwa"]=>
NULL
["tel"]=>
NULL
["fax"]=>
NULL
["email"]=>
NULL
["www"]=>
NULL
["modified"]=>
NULL
["deleted"]=>
NULL
["cro_type_id"]=>
NULL
["displayName"]=>
NULL
["objectTypeIdWithId"]=>
NULL
}
["Attachment"]=>
array(0) {
}
["Specialization"]=>
array(0) {
}
["Obk"]=>
array(1) {
[0]=>
array(13) {
["id"]=>
int(3)
["nazwa"]=>
string(10) "OBK Z ID 3"
["tel"]=>
string(13) "+48 123456890"
["fax"]=>
string(13) "+48 123456789"
["email"]=>
string(15) "EMAIL#EMAIL.COM"
["www"]=>
string(11) "WWW.WWW.WWW"
["modified"]=>
string(22) "2017-03-20 10:45:24+01"
["created"]=>
string(22) "2014-05-16 09:09:33+02"
["deleted"]=>
int(0)
["local_order"]=>
int(1)
["displayName"]=>
string(10) "OBK Z ID 3"
["objectTypeIdWithId"]=>
string(3) "2_3"
["PeopleObk"]=>
array(3) {
["id"]=>
int(2)
["person_id"]=>
int(3)
["obk_id"]=>
int(3)
}
}
}
}
And I want just to retrieve Person.id, Person.displayName and Obk.0.id. The two first are no problem, but wheneve I try to get Obk.0.id I'm getting error: SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM for Table Obk.
How can I get something like that? I want to set the value in codition later, but it block my work.
In CakePHP 2 you can specify the fields you want returned by a find() query using the fields option like:-
$this->Foo->find('all', [
'fields' => ['Foo.id', 'Foo.name']
]);
This also works with contained models that have a belongsTo or hasOne relationship:-
$this->Foo->find('all', [
'fields' => ['Foo.id', 'Foo.name', 'Bar.name'],
'contain' => ['Bar']
]);
However, if the contained model is a hasMany or HABTM relationship you need to specify the fields of that model on the contain:-
$this->Foo->find('all', [
'fields' => ['Foo.id', 'Foo.name'],
'contain' => [
'Bar' => ['fields' => 'Bar.name']
]
]);
This is because CakePHP will be performing multiple SQL queries, so the contain needs to have the parameters for the query being run for the relevant model.
first I'm looking help from any expert here for PHP array calling. I try using var_dump but still I can't call my data. I'm really a beginner and need a lot of help. Thanks before for read my question below...
<?php var_dump($this->product->customfieldsSorted); ?>
I use that and get this array list...
array(1) {
["normal"]=>
array(1) {
[0]=>
object(stdClass)#222 (36) {
["virtuemart_custom_id"]=>
string(2) "21"
["custom_parent_id"]=>
string(1) "0"
["virtuemart_vendor_id"]=>
string(1) "1"
["custom_jplugin_id"]=>
string(1) "0"
["custom_element"]=>
string(0) ""
["admin_only"]=>
string(1) "0"
["custom_title"]=>
string(5) "Slide"
["show_title"]=>
string(1) "0"
["custom_tip"]=>
string(0) ""
["custom_value"]=>
string(0) ""
["custom_desc"]=>
string(0) ""
["field_type"]=>
string(1) "M"
["is_list"]=>
string(1) "0"
["is_hidden"]=>
string(1) "1"
["is_cart_attribute"]=>
string(1) "0"
["is_input"]=>
string(1) "0"
["layout_pos"]=>
string(0) ""
["custom_params"]=>
string(26) "width="1024"|height="400"|"
["shared"]=>
string(1) "0"
["published"]=>
string(1) "1"
["ordering"]=>
string(1) "0"
["virtuemart_customfield_id"]=>
string(3) "110"
["virtuemart_product_id"]=>
string(2) "95"
["customfield_value"]=>
string(2) "15"
["customfield_price"]=>
NULL
["customfield_params"]=>
string(25) "width="200"|height="200"|"
["fpublished"]=>
string(1) "0"
["override"]=>
string(1) "0"
["disabler"]=>
string(1) "0"
["_varsToPushParamCustom"]=>
array(2) {
["width"]=>
array(2) {
[0]=>
string(3) "200"
[1]=>
string(6) "string"
}
["height"]=>
array(2) {
[0]=>
string(3) "200"
[1]=>
string(6) "string"
}
}
["_varsToPushParamCustomField"]=>
array(2) {
["width"]=>
array(2) {
[0]=>
string(3) "200"
[1]=>
string(6) "string"
}
["height"]=>
array(2) {
[0]=>
string(3) "200"
[1]=>
string(6) "string"
}
}
["_varsToPushParam"]=>
array(2) {
["width"]=>
array(2) {
[0]=>
string(3) "200"
[1]=>
string(6) "string"
}
["height"]=>
array(2) {
[0]=>
string(3) "200"
[1]=>
string(6) "string"
}
}
["width"]=>
string(3) "200"
["height"]=>
string(3) "200"
["_xParams"]=>
string(18) "customfield_params"
["display"]=>
string(101) "<img src="/angga/images/stories/virtuemart/product/resized/marinecap_200x200.jpg" alt="marinecap" />"
}
}
Nah I want to get the:
["display"]=>
string(101) "<img src="/angga/images/stories/virtuemart/product/resized/marinecap_200x200.jpg" alt="marinecap" />"
using this:
<?php echo $this->product->customfieldsSorted->display;?>
and got nothing. Can anyone help? I have no clue. None at all. Thanks before :)
$this->product->customfieldsSorted is an array with the key "normal", you can get corresponding value: $this->product->customfieldsSorted['normal'].
$this->product->customfieldsSorted['normal'] is an array with the key 0, get its value: $this->product->customfieldsSorted['normal'][0].
$this->product->customfieldsSorted['normal'][0] is an object of stdClass, you can get value of the property display using $this->product->customfieldsSorted['normal'][0]->display.
I have the array like this:
} ["items":"Jcart":private]=> array(3) {
[0]=>
string(1) "3"
[1]=>
string(1) "2"
[2]=>
string(7) "ABC-123" }
How to get the "items" values in a php variable?
///////
Te complete object is:
object(Jcart)#1 (8) {
["config"]=>
array(12) {
["jcartPath"]=>
string(6) "jcart/"
["checkoutPath"]=>
string(12) "checkout.php"
["item"]=>
array(6) {
["id"]=>
string(10) "my-item-id"
["name"]=>
string(12) "my-item-name"
["price"]=>
string(13) "my-item-price"
["qty"]=>
string(11) "my-item-qty"
["url"]=>
string(11) "my-item-url"
["add"]=>
string(13) "my-add-button"
}
["paypal"]=>
array(5) {
["id"]=>
string(38) "seller_1282188508_biz#conceptlogic.com"
["https"]=>
bool(true)
["sandbox"]=>
bool(false)
["returnUrl"]=>
string(0) ""
["notifyUrl"]=>
string(0) ""
}
["currencyCode"]=>
string(3) "USD"
["csrfToken"]=>
bool(false)
["text"]=>
array(14) {
["cartTitle"]=>
string(13) "Shopping Cart"
["singleItem"]=>
string(4) "Item"
["multipleItems"]=>
string(5) "Items"
["subtotal"]=>
string(8) "Subtotal"
["update"]=>
string(6) "update"
["checkout"]=>
string(8) "checkout"
["checkoutPaypal"]=>
string(20) "Checkout with PayPal"
["removeLink"]=>
string(6) "remove"
["emptyButton"]=>
string(5) "empty"
["emptyMessage"]=>
string(19) "Your cart is empty!"
["itemAdded"]=>
string(11) "Item added!"
["priceError"]=>
string(21) "Invalid price format!"
["quantityError"]=>
string(38) "Item quantities must be whole numbers!"
["checkoutError"]=>
string(34) "Your order could not be processed!"
}
["button"]=>
array(4) {
["checkout"]=>
string(0) ""
["paypal"]=>
string(0) ""
["update"]=>
string(0) ""
["empty"]=>
string(0) ""
}
["tooltip"]=>
bool(true)
["decimalQtys"]=>
bool(false)
["decimalPlaces"]=>
int(1)
["priceFormat"]=>
array(3) {
["decimals"]=>
int(2)
["dec_point"]=>
string(1) "."
["thousands_sep"]=>
string(1) ","
}
}
["items":"Jcart":private]=>
array(2) {
[0]=>
string(1) "3"
[1]=>
string(1) "2"
}
["names":"Jcart":private]=>
array(2) {
[3]=>
string(12) "Hockey Stick"
[2]=>
string(13) "Baseball Mitt"
}
["prices":"Jcart":private]=>
array(2) {
[3]=>
string(5) "33.25"
[2]=>
string(5) "19.50"
}
["qtys":"Jcart":private]=>
array(2) {
[3]=>
string(1) "1"
[2]=>
string(2) "20"
}
["urls":"Jcart":private]=>
array(2) {
[3]=>
string(15) "http://bing.com"
[2]=>
string(16) "http://yahoo.com"
}
["subtotal":"Jcart":private]=>
float(423.25)
["itemCount":"Jcart":private]=>
int(21)
}
I just need the values in ["items":"Jcart":private]
I assume you got this by casting an object to an array. If that's the case, you shouldn't be doing that! The property is private because you're not supposed to access it directly because it's not a public API. The object should have a public method which you're supposed to call instead, that's the public API. Something like $foo->getItems() or such. Read the documentation and/or source code.
I am trying to get some value from the massive array, and there occured some problem.
I have such array:
array(2) {
[0]=>
array(23) {
["ITEM_ID"]=>
int(2331)
["ITEM_TYPE_ID"]=>
string(1) "1"
["CART_ITEM_ID"]=>
string(0) ""
["SAVED_TYPE_ID"]=>
string(0) ""
["ITEM_NAME"]=>
string(17) "TEST STOCK LEVELS"
["ERROR"]=>
string(0) ""
["PROPERTIES"]=>
array(1) {
[522]=>
array(1) {
[0]=>
string(4) "1122"
}
}
["PROPERTIES_INFO"]=>
array(1) {
[522]=>
array(12) {
["USAGE_TYPE"]=>
string(1) "1"
["CONTROL"]=>
string(7) "LISTBOX"
["TYPE"]=>
string(1) "1"
["NAME"]=>
string(11) "TEST OPTION"
["VALUES"]=>
array(1) {
[0]=>
string(4) "1122"
}
["REQUIRED"]=>
string(1) "1"
["PARENT_PROPERTY_ID"]=>
string(0) ""
["PARENT_VALUE_ID"]=>
string(0) ""
["TEXT"]=>
array(0) {
}
["CONTROL_PRICE"]=>
int(0)
["ORDER"]=>
string(1) "1"
["QUANTITY_ACTION"]=>
string(1) "1"
}
}
["PROPERTIES_PRICE"]=>
float(10)
["PROPERTIES_PERCENTAGE"]=>
int(0)
["PROPERTIES_BUYING"]=>
int(0)
["PROPERTIES_DISCOUNT"]=>
int(0)
["PROPERTIES_MORE"]=>
string(1) "0"
["COMPONENTS"]=>
array(0) {
}
["QUANTITY"]=>
int(11)
["TAX_FREE"]=>
string(1) "0"
["DISCOUNT"]=>
int(1)
["BUYING_PRICE"]=>
string(0) ""
["PRICE_EDIT"]=>
string(1) "0"
["PRICE"]=>
string(5) "10.00"
["CHECK_PRICE"]=>
float(20)
["MAX_ITEM_DISCOUNT"]=>
float(20)
["CART_PRICE"]=>
float(20)
}
[1]=>
array(23) {
["ITEM_ID"]=>
int(2331)
["ITEM_TYPE_ID"]=>
string(1) "1"
["CART_ITEM_ID"]=>
string(0) ""
["SAVED_TYPE_ID"]=>
string(0) ""
["ITEM_NAME"]=>
string(17) "TEST STOCK LEVELS"
["ERROR"]=>
string(0) ""
["PROPERTIES"]=>
array(1) {
[522]=>
array(1) {
[0]=>
string(4) "1123"
}
}
["PROPERTIES_INFO"]=>
array(1) {
[522]=>
array(12) {
["USAGE_TYPE"]=>
string(1) "1"
["CONTROL"]=>
string(7) "LISTBOX"
["TYPE"]=>
string(1) "1"
["NAME"]=>
string(11) "TEST OPTION"
["VALUES"]=>
array(1) {
[0]=>
string(4) "1123"
}
["REQUIRED"]=>
string(1) "1"
["PARENT_PROPERTY_ID"]=>
string(0) ""
["PARENT_VALUE_ID"]=>
string(0) ""
["TEXT"]=>
array(0) {
}
["CONTROL_PRICE"]=>
int(0)
["ORDER"]=>
string(1) "1"
["QUANTITY_ACTION"]=>
string(1) "1"
}
}
["PROPERTIES_PRICE"]=>
float(20)
["PROPERTIES_PERCENTAGE"]=>
int(0)
["PROPERTIES_BUYING"]=>
int(0)
["PROPERTIES_DISCOUNT"]=>
int(0)
["PROPERTIES_MORE"]=>
string(1) "0"
["COMPONENTS"]=>
array(0) {
}
["QUANTITY"]=>
int(5)
["TAX_FREE"]=>
string(1) "0"
["DISCOUNT"]=>
int(1)
["BUYING_PRICE"]=>
string(0) ""
["PRICE_EDIT"]=>
string(1) "0"
["PRICE"]=>
string(5) "10.00"
["CHECK_PRICE"]=>
float(30)
["MAX_ITEM_DISCOUNT"]=>
float(30)
["CART_PRICE"]=>
float(30)
}
}
Before looping this array, I receive some property_id (1123 for example).
I need to check if this property_id matches this element (1122 in my case)
["PROPERTIES"]=>
array(1) {
[522]=>
array(1) {
[0]=>
string(4) "1122"
}
}
then select its quantity property (in my case it is this element)
["QUANTITY"]=>
int(11)
The problem is to identify from which arrays select this property, because first I need to compare my received value with existing in array(1122 in my case).
I think you could do it faster with a better organized array. As it is I'll do a loop.
Something like that :
$quantity = 0;
$which_array = -1;
foreach($massive as $key=>$value){
if(isset($value['PROPERTIES_INFO'])){
$copy_properties = $value['PROPERTIES_INFO'];
$property_first = reset($copy_properties);
$id_property = key($property_first);
if($id_property == $what_id_you_are_looking_for){
$quantity = $value['QUANTITY'];//delete one of this
//or I don't know wich quantity you want so I put them both
$quantity = $value['PROPERTIES_INFO'][$id_property ]['QUANTITY_ACTION'];//delete one of this
$which_array = $key;
break;
}
}
}