Extract $item code from array in k2store - php

I try to extract and to show on the page with echo product code field in K2store cart page (store extension for K2 for Joomla) but without success. The right value is "product_code" or "code" (is the same value): 26910.
Both "echo $item->product_name" and "echo $item->product_id" works, but "echo $item->code" and "echo $item->product_code" return NULL.
var_dump($item) show me this:
object(stdClass)#381 (13) {
["key"]=>
int(9928417)
["product_id"]=>
string(7) "9928417"
["product_name"]=>
string(71) "some title"
["product_model"]=>
NULL
["product_total"]=>
int(1)
["product_options"]=>
object(stdClass)#382 (0) {
}
["quantity"]=>
int(1)
["stock"]=>
object(JObject)#378 (18) {
["_errors":protected]=>
array(0) {
}
["item_enabled"]=>
string(1) "1"
["item_sku"]=>
NULL
["item_price"]=>
NULL
["special_price"]=>
NULL
["item_tax_id"]=>
NULL
["item_shipping"]=>
NULL
["item_qty"]=>
NULL
["item_cart_text"]=>
NULL
["product_id"]=>
string(7) "9928417"
["product_name"]=>
string(71) "some title"
["product_code"]=>
string(5) "26910"
["price"]=>
NULL
["product_sku"]=>
NULL
["tax_profile_id"]=>
NULL
["item_minimum"]=>
string(1) "1"
["stock"]=>
*RECURSION*
["product"]=>
object(stdClass)#354 (38) {
["id"]=>
string(7) "9928417"
["code"]=>
string(5) "26910"
["title"]=>
string(71) "some title"
["alias"]=>
string(71) "some title"
["catid"]=>
string(3) "694"
["published"]=>
string(1) "1"
["introtext"]=>
string(0) ""
["fulltext"]=>
string(0) ""
["video"]=>
NULL
["gallery"]=>
NULL
["extra_fields"]=>
string(29) "[{"id":"1","value":"25\/40"}]"
["extra_fields_search"]=>
string(6) "25/40 "
["created"]=>
string(19) "2012-09-14 10:20:09"
["created_by"]=>
string(2) "52"
["created_by_alias"]=>
string(0) ""
["checked_out"]=>
string(1) "0"
["checked_out_time"]=>
string(19) "0000-00-00 00:00:00"
["modified"]=>
string(19) "2012-09-14 10:30:46"
["modified_by"]=>
string(2) "52"
["publish_up"]=>
string(19) "2012-09-14 10:20:09"
["publish_down"]=>
string(19) "0000-00-00 00:00:00"
["trash"]=>
string(1) "0"
["access"]=>
string(1) "1"
["ordering"]=>
string(1) "1"
["featured"]=>
string(1) "0"
["featured_ordering"]=>
string(1) "0"
["image_caption"]=>
string(0) ""
["image_credits"]=>
string(0) ""
["video_caption"]=>
string(0) ""
["video_credits"]=>
string(0) ""
["hits"]=>
string(5) "17852"
["params"]=>
string(1190) "catItemTitle=
catItemTitleLinked=
catItemFeaturedNotice=
catItemAuthor=
catItemDateCreated=
catItemRating=
catItemImage=
catItemIntroText=
catItemExtraFields=
catItemHits=
catItemCategory=
catItemTags=
catItemAttachments=
catItemAttachmentsCounter=
catItemVideo=
catItemVideoWidth=
catItemVideoHeight=
catItemVideoAutoPlay=
catItemImageGallery=
catItemDateModified=
catItemReadMore=
catItemCommentsAnchor=
catItemK2Plugins=
itemDateCreated=
itemTitle=
itemFeaturedNotice=
itemAuthor=
itemFontResizer=
itemPrintButton=
itemEmailButton=
itemSocialButton=
itemVideoAnchor=
itemImageGalleryAnchor=
itemCommentsAnchor=
itemRating=
itemImage=
itemImgSize=
itemImageMainCaption=
itemImageMainCredits=
itemIntroText=
itemFullText=
itemExtraFields=
itemDateModified=
itemHits=
itemTwitterLink=
itemCategory=
itemTags=
itemShareLinks=
itemAttachments=
itemAttachmentsCounter=
itemRelated=
itemRelatedLimit=
itemVideo=
itemVideoWidth=
itemVideoHeight=
itemVideoAutoPlay=
itemVideoCaption=
itemVideoCredits=
itemImageGallery=
itemNavigation=
itemComments=
itemAuthorBlock=
itemAuthorImage=
itemAuthorDescription=
itemAuthorURL=
itemAuthorEmail=
itemAuthorLatest=
itemAuthorLatestLimit=
itemK2Plugins=
"
["metadesc"]=>
string(0) ""
["metadata"]=>
string(15) "robots=
author="
["metakey"]=>
string(0) ""
["plugins"]=>
string(27) "{"k2storeitem_enabled":"1"}"
["code_search"]=>
string(0) ""
["language"]=>
string(0) ""
}
}
["tax_amount"]=>
int(0)
["price"]=>
int(0)
["price_without_tax"]=>
int(0)
["total"]=>
int(0)
["total_without_tax"]=>
int(0)
}

The solution is: $item->stock->product_code

Related

print ckeditor content from mysql

I am trying to print my content from the ckeditor I uploaded to the db.
In the admin panel editing ckeditor it's normal,
but once I print it in the site via:
<?if (!empty($show['participants'])){?>
<Div class="participants">
<?=$show['participants']?>
</Div>
<?}?>
It's echo the tags only:
<p><strong>אנדרס מוסטונן</strong>, מנצח (אסטוניה)<br><strong>קרן הדר, </strong>סופרן (ישראל)<br><strong>ארה סאל</strong>, בריטון (אסטוניה)<br><strong>מקהלת עמק חפר </strong><br><strong>מקהלה אסטונית</strong><br><br><br><strong>בתוכנית:</strong><br><strong>אורף</strong>: כרמינה בורנה<br><strong>יואב תלמי</strong>: אלגריה למיתרים, טימפני ואקורדיון</p>
Var dumped $show:
array(27) { ["id"]=> string(3) "432" ["code"]=> string(36) "63c8bc24-f730-e811-bd2b-10604ba9908f" ["name"]=> string(10) "הקיסר" ["title_short"]=> string(163) "מפגש ענקים - כריסטיאן יארווי ורומן רבינוביץ' בביצוע "הפנטסטית" של ברליוז ו"הקיסר" של בטהובן" ["title_long"]=> string(0) "" ["description"]=> string(29) "<p> </p>" ["participants"]=> string(612) "<p><strong>כריסטיאן יארווי</strong>,מנצח (אסטוניה)<br><strong>רומן רבינוביץ'</strong>, פסנתר (ישראל)<br><br><strong>בתוכנית:</strong><br><strong>בן חיים</strong>: "תרועה לישראל"<br><strong>בטהובן</strong>: קונצ'רטו לפסנתר מס' 5 – הקיסר<br><strong>ברליוז</strong>: סימפוניה פנטסטית<br><strong>ארוו פרט</strong>: Fratres</p>" ["image"]=> string(11) "keisarx.jpg" ["image_banner"]=> string(15) "julioskeiar.jpg" ["img_credits"]=> string(18) "בלש בורוץ'" ["video"]=> string(0) "" ["category_id"]=> string(2) "60" ["category_order"]=> string(1) "0" ["show_on_main"]=> string(1) "1" ["main_order"]=> string(1) "2" ["show_on_slide"]=> string(1) "0" ["slide_order"]=> string(1) "1" ["home_page"]=> NULL ["direct_link"]=> string(58) "http://tickets.isorl.co.il/he-IL/shows/הקיסר/events/1" ["english_name"]=> NULL ["english_direct_link"]=> NULL ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["update_auto_timestamp"]=> string(19) "2018-09-02 12:12:33" ["active"]=> string(1) "1" ["is_amfi_show"]=> string(1) "0" ["is_kunhiya_show"]=> string(1) "0" ["events"]=> array(3) { ["by_id"]=> array(2) { [1191]=> &array(20) { ["id"]=> string(4) "1191" ["code"]=> string(36) "e7869a2b-ff30-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-07" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(43) "היכל התרבות ראשון לציון" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(99) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-7_20.00/היכל ראשון לציון/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3709" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } [1193]=> &array(20) { ["id"]=> string(4) "1193" ["code"]=> string(36) "49a650f7-f630-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-09" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(71) "המשכן לאמנויות הבמה, בית האופרה תל אביב" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(88) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-9_20.00/בית האופרה/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3695" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } } ["by_order"]=> array(2) { [0]=> &array(20) { ["id"]=> string(4) "1191" ["code"]=> string(36) "e7869a2b-ff30-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-07" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(43) "היכל התרבות ראשון לציון" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(99) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-7_20.00/היכל ראשון לציון/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3709" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } [1]=> &array(20) { ["id"]=> string(4) "1193" ["code"]=> string(36) "49a650f7-f630-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-09" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(71) "המשכן לאמנויות הבמה, בית האופרה תל אביב" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(88) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-9_20.00/בית האופרה/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3695" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } } ["by_date"]=> array(2) { ["2018-10-07"]=> array(1) { [0]=> &array(20) { ["id"]=> string(4) "1191" ["code"]=> string(36) "e7869a2b-ff30-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-07" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(43) "היכל התרבות ראשון לציון" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(99) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-7_20.00/היכל ראשון לציון/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3709" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } } ["2018-10-09"]=> array(1) { [0]=> &array(20) { ["id"]=> string(4) "1193" ["code"]=> string(36) "49a650f7-f630-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-09" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(71) "המשכן לאמנויות הבמה, בית האופרה תל אביב" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(88) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-9_20.00/בית האופרה/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3695" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } } } } }
What is going wrong? Thanks.

PHP Fatal error out of memory while building tree

I got trouble with bulding tree of categories in php.
It's builds tree for very long time and after that i got error:
Fatal error: Out of memory (allocated 637796352) (tried to allocate
208666926 bytes) in
D:\OpenServer\domains\site.local\Core\Widgets.php on line 488
Here is my functions to build tree.
First i made an array of categories:
public function makeCategoriesArray()
{
// $row = DB::select()
// ->from('catalog_tree')
// ->where('parent_id', '=', $this->post['parent_id'])
// ->union(DB::select()
// ->from('catalog_tree')
// ->where('id', 'in', DB::expr("(SELECT catalog_tree_id FROM catalog_tree_parents WHERE parent_id = '".$this->post['parent_id']."')")))
// ->find_all();
$row = DB::select()
->from('catalog_tree')
->where('status', '=', '1')
->find_all();
$categories_arr = array();
foreach ($row as $cat) {
$categories_arr[$cat->parent_id][] = $cat;
}
unset($cat);
unset($row);
foreach($categories_arr as $key=>$value) {
$row = DB::select()
->from('catalog_tree')
->where('id', 'in', DB::expr("(SELECT catalog_tree_id FROM catalog_tree_parents WHERE parent_id = '".$key."')"))
->find_all();
foreach($row as $cat) {
$categories_arr[$key][] = $cat;
}
unset($cat);
unset($row);
}
return $categories_arr;
}
Then i begin to build tree with this array:
public function BuildMainTree($array, $pid) {
global $MainMenu;
if (isset($array[$pid])) { // If category with $pid exist
$MainMenu.= "<ul class=\"dropdown-menu\" role=\"menu\">";
foreach ($array[$pid] as $value)
{
if ($pid!='0' && !isset($array[$value->id])) {
$MainMenu.= '<li class="divider"></li>
<li class="dropdown">
<a href="/catalog/' . $value->alias . '">
'. $value->name .'
</a>
</li>';
}
else {
$MainMenu.= '<li class="divider"></li>
<li class="dropdown">
<a href="/catalog/' . $value->alias . '">
'. $value->name .'
<span class="caret"></span>
</a>
</li>';
$this->BuildMainTree($array, $value->id);
}
}
if ($pid=='0') {
$MainMenu .= "</ul>";
}
else {
$MainMenu .= "</ul></li>";
}
}
}
Initialization of this process are in this function:
public function Header() {
$contentMenu = Common::factory('sitemenu')->getRows(1, 'sort');
$array['contentMenu'] = $contentMenu;
$array['user'] = User::info();
$array['countItemsInTheCart'] = Cart::factory()->_count_goods;
$categories_arr = $this->makeCategoriesArray();
$this->BuildMainTree($categories_arr, 0);
$array['mainMenu'] = $MainMenu;
return $array;
}
Also if i just make array with makeCategoriesArray() it's works fine, but BuildMainTree($array, $pid) function causes an error...
Most funny part, is that this code works perfect on other site.
Maybe I just missed some details here... Spent two days of tried to run this code, but got nothing.
Here is array var_dump:
array(156) {
[0]=>
array(21) {
[0]=>
object(stdClass)#17 (18) {
["id"]=>
string(4) "2075"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1473775697"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(27) "Садовая мебель"
["alias"]=>
string(14) "sadovaja-mebel"
["ikea_alias"]=>
string(7) "outdoor"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "dc30302d5e76ddf7d3be9cb0f8b4d711.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "129"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[1]=>
object(stdClass)#19 (18) {
["id"]=>
string(4) "2076"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1473950659"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(39) "Оформление интерьера"
["alias"]=>
string(19) "oformlenie-interera"
["ikea_alias"]=>
string(10) "decoration"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "91b3786d06e22081abbb945b9e4e02d8.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "287"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[2]=>
object(stdClass)#20 (18) {
["id"]=>
string(4) "2077"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472474523"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(27) "Офисная мебель"
["alias"]=>
string(14) "ofisnaja-mebel"
["ikea_alias"]=>
string(10) "workspaces"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "6884cb6cf5defdf8ec7fe467bad542ca.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "247"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[3]=>
object(stdClass)#21 (18) {
["id"]=>
string(4) "2078"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472409476"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(34) "Посуда для готовки"
["alias"]=>
string(19) "posuda-dlja-gotovki"
["ikea_alias"]=>
string(7) "cooking"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "ca3e4a8eb9d0d7ea22f9a7fc3c300ef9.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "514"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[4]=>
object(stdClass)#22 (18) {
["id"]=>
string(4) "2079"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472547042"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(16) "Столовая"
["alias"]=>
string(9) "stolovaja"
["ikea_alias"]=>
string(6) "dining"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "d5704ec3e70a3415b181c7c4f9005c1a.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "147"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[5]=>
object(stdClass)#23 (18) {
["id"]=>
string(4) "2080"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472547236"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(31) "Сервировка стола"
["alias"]=>
string(16) "servirovka-stola"
["ikea_alias"]=>
string(6) "eating"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "2d2142a8edd5fc3ce1ffa01fbe6655c9.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "338"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[6]=>
object(stdClass)#24 (18) {
["id"]=>
string(4) "2081"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472540142"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(21) "Кухни МЕТОД"
["alias"]=>
string(11) "kuhni-metod"
["ikea_alias"]=>
string(7) "kitchen"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "decf1d321c63aed673d949b34c452a37.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "304"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[7]=>
object(stdClass)#25 (18) {
["id"]=>
string(4) "2082"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472466401"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(18) "Освещение"
["alias"]=>
string(11) "osveschenie"
["ikea_alias"]=>
string(8) "lighting"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "3ac3d00a4734040cf346f2a63a09a7f9.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "243"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[8]=>
object(stdClass)#26 (18) {
["id"]=>
string(4) "2083"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472547518"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(14) "Детская"
["alias"]=>
string(8) "detskaja"
["ikea_alias"]=>
string(14) "childrens_ikea"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "8d78781b99b8ee7a1abc0f9cbfdc7e01.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "321"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[9]=>
object(stdClass)#27 (18) {
["id"]=>
string(4) "2084"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472411322"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(16) "Гостиная"
["alias"]=>
string(9) "gostinaja"
["ikea_alias"]=>
string(11) "living_room"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "c9c933ae12652bca96eb2ef66c832a82.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "181"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[10]=>
object(stdClass)#28 (18) {
["id"]=>
string(4) "2085"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472388754"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(35) "Домашняя прачечная"
["alias"]=>
string(24) "domashnjaja-prachechnaja"
["ikea_alias"]=>
string(7) "laundry"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "08c9713d828235679b861c095784af0e.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "106"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[11]=>
object(stdClass)#29 (18) {
["id"]=>
string(4) "2086"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472481068"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(45) "Дополнительное хранение"
["alias"]=>
string(22) "dopolnitelnoe-hranenie"
["ikea_alias"]=>
string(17) "secondary_storage"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "bb180b85cc1e34ab9b6185f4cf71fbf0.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "158"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[12]=>
object(stdClass)#31 (18) {
["id"]=>
string(4) "2088"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472136224"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(16) "Прихожая"
["alias"]=>
string(10) "prihozhaja"
["ikea_alias"]=>
string(7) "hallway"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "985600d075b4080f57488b87e0e898ff.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(2) "64"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[13]=>
object(stdClass)#32 (18) {
["id"]=>
string(4) "2089"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472556911"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(14) "Спальня"
["alias"]=>
string(7) "spalnja"
["ikea_alias"]=>
string(7) "bedroom"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "439a1f90391568bffabcfbc5a8b22559.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "172"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[14]=>
object(stdClass)#33 (18) {
["id"]=>
string(4) "2090"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472481070"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(18) "Еда в ИКЕА"
["alias"]=>
string(10) "eda-v-ikea"
["ikea_alias"]=>
string(4) "food"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "1886868c925ed2f22a10fe7e51a6050c.JPG"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(2) "24"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[15]=>
object(stdClass)#34 (18) {
["id"]=>
string(4) "2091"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472554267"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(16) "Текстиль"
["alias"]=>
string(7) "tekstil"
["ikea_alias"]=>
string(8) "Textiles"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "1ed5b13bc1abab2d5966b6ab074b7174.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "194"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[16]=>
object(stdClass)#35 (18) {
["id"]=>
string(4) "2092"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1473774214"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(33) "Домашние растения"
["alias"]=>
string(19) "domashnie-rastenija"
["ikea_alias"]=>
string(16) "indoor_gardening"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "a42bf2728494d635bc16b0f12db5855d.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
string(0) ""
["views"]=>
string(2) "55"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[17]=>
object(stdClass)#36 (18) {
["id"]=>
string(4) "2093"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472481066"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(39) "Беспроводная зарядка"
["alias"]=>
string(22) "besprovodnaja-zarjadka"
["ikea_alias"]=>
string(17) "wireless_charging"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "6ee6de2d3769d7f617b7e05fd81fbaa4.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(2) "95"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[18]=>
object(stdClass)#37 (18) {
["id"]=>
string(4) "2094"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472517463"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(12) "Ванная"
["alias"]=>
string(7) "vannaja"
["ikea_alias"]=>
string(8) "bathroom"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "f69159cedca764bc7d44ff7d6a13b52a.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "157"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[19]=>
object(stdClass)#38 (18) {
["id"]=>
string(4) "2095"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472379447"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(24) "Товары IKEA FAMILY"
["alias"]=>
string(18) "tovary-ikea-family"
["ikea_alias"]=>
string(20) "ikea_family_products"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "9e0c8d67fd4189ebed7b821e1c6b9df8.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(2) "78"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[20]=>
object(stdClass)#39 (18) {
["id"]=>
string(4) "2096"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472482584"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(34) "Для вашего бизнеса"
["alias"]=>
string(20) "dlja-vashego-biznesa"
["ikea_alias"]=>
string(8) "business"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "3b9d8f1d77703f38d3d043fb95dd2b5e.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "118"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
}
that is not a code issue. set memory_limit in php.ini file to more than 128m,
you should also increase post meta data to something like 10000
Problem solved with this function:
public static function BuildTree($pid) {
global $MainMenu;
$row = DB::select()
->from('catalog_tree')
->where('parent_id', '=', $pid)
->and_where('status', '=', '1')
->union(DB::select()
->from('catalog_tree')
->where('id', 'in', DB::expr("(SELECT catalog_tree_id FROM catalog_tree_parents WHERE parent_id = '".$pid."')"))
->and_where('status', '=', '1'))
->find_all();
if ($row->count() > 0) {
$MainMenu .= "<ul class=\"dropdown-menu\" role=\"menu\">";
foreach ($row as $value)
{
$MainMenu .= '
<li class="divider"></li>
<li class="dropdown">
<a href="/catalog/' . $value->alias . '">
'. $value->name .'
</a> ';
Widgets::BuildTree($value->id);
}
if ($pid=='0') {
$MainMenu .= " <li class=\"divider\"></li></ul>";
return $MainMenu;
}
else {
$MainMenu .= " <li class=\"divider\"></li></ul></li>";
}
}
}
This function works perfectly :)
I think #DoktorOSwaldo was right, previous recursion was endless.

how to fetch value from array_chunk function

I'm using array_chunk function:
<?php
$chunks = array_chunk($coupons, 2,true);
?>
#foreach($chunks as $k => $c )
#if(2 == sizeof($c))
$c[0]['tr']->coupon_code
but the blow code not works fine :
$c[0]['tr']->coupon_code
or
$c[0]['tr']['coupon_code']
the content of var_dump($c):
array(2) { [217517]=> array(3) { ["tr"]=> object(stdClass)#71 (30) { ["id"]=> string(6) "217517" ["price"]=> string(5) "14400" ["date"]=> string(19) "2016-01-16 11:13:13" ["user_id"]=> string(5) "16433" ["ip"]=> string(14) "46.225.196.181" ["code"]=> string(13) "5699f4917b9c3" ["succ"]=> string(1) "1" ["admin_seen"]=> string(1) "0" ["user_seen"]=> string(1) "0" ["coupon_id"]=> string(5) "15373" ["coupon_parent"]=> string(5) "15315" ["coupon_code"]=> string(20) "24_1117C1_4644(1453)" ["coupon_code_user"]=> string(4) "1453" ["coupon_code_partner"]=> string(14) "24_1117C1_4644" ["shop_id"]=> string(4) "1117" ["payment_type"]=> string(1) "7" ["merchent_type"]=> string(1) "3" ["merchent_id"]=> string(1) "0" ["cradit_start_date"]=> string(19) "2015-12-29 05:05:05" ["cradit_end_date"]=> string(19) "2016-02-19 05:05:05" ["expired"]=> string(1) "0" ["pay_data"]=> NULL ["seri"]=> string(1) "C" ["to_friend"]=> string(1) "0" ["finance_id"]=> string(1) "0" ["app"]=> string(3) "web" ["expire_date"]=> string(19) "0000-00-00 00:00:00" ["expire_app"]=> string(0) "" ["buy_id"]=> string(13) "5699f4913103e" ["coupon_property_id"]=> string(3) "195" } ["offer"]=> object(stdClass)#67 (46) { ["id"]=> string(5) "15373" ["title"]=> string(21) "طرح دخترانه" ["slider_title"]=> string(0) "" ["short_title"]=> string(0) "" ["pic"]=> string(25) "Bracelets-off-Greek31.jpg" ["text"]=> string(0) "" ["attrs"]=> string(0) "" ["jest"]=> string(0) "" ["terms_of_use"]=> string(0) "" ["how_to_use"]=> string(0) "" ["city"]=> string(0) "" ["price"]=> string(5) "45000" ["off"]=> string(2) "68" ["min_users"]=> string(1) "0" ["max_users"]=> string(1) "0" ["current_users"]=> string(1) "2" ["expire"]=> string(1) "0" ["sell_start_date"]=> string(19) "2015-12-29 01:00:00" ["sell_end_date"]=> string(19) "2016-01-26 15:00:00" ["cradit_start_date"]=> string(19) "0000-00-00 00:00:00" ["cradit_end_date"]=> string(19) "0000-00-00 00:00:00" ["admin_expire_date"]=> string(19) "0000-00-00 00:00:00" ["showin_other"]=> string(1) "0" ["showin_slider"]=> string(1) "0" ["showin_slider_cat"]=> string(1) "0" ["moment"]=> string(1) "0" ["seri"]=> string(1) "C" ["shop_id"]=> string(4) "1117" ["tractions"]=> string(1) "0" ["status"]=> string(1) "0" ["url"]=> string(0) "" ["shadyab_profit"]=> string(4) "6400" ["fake_sell"]=> string(1) "3" ["confirm"]=> string(1) "0" ["adviser"]=> string(1) "0" ["parent"]=> string(5) "15315" ["description"]=> string(0) "" ["old"]=> string(1) "0" ["email_text"]=> string(0) "" ["zone"]=> string(0) "" ["views"]=> string(1) "0" ["max_buy"]=> string(1) "0" ["likes"]=> string(1) "0" ["alt"]=> string(70) "فروشگاه گیوا گالری, خرید اینترنتی کالا" ["sizes"]=> string(0) "" ["name"]=> string(11) "مدل ها" } ["details"]=> object(stdClass)#66 (22) { ["id"]=> string(6) "205585" ["tr_id"]=> string(6) "217517" ["title"]=> string(59) "دستبند چرم پلاک استیل طرح فانتزی" ["short_title"]=> string(0) "" ["pic"]=> string(17) "dastband_(2)1.jpg" ["text"]=> string(627) "
Problem here is that you preserve keys form original array. So, you don't have 0 or 1 key in a chunk $c.
Either you do not preserve keys $chunks = array_chunk($coupons, 2) as you have id in a tr object within id property and use $c[0]['tr']->coupon_code
Or you should get keys of a chunk $c with array_keys for example:
foreach($chunks as $k => $c) {
$keys = array_keys($c);
echo $c[$keys[0]]['tr']->coupon_code;
}
$c[0]['tr']['coupon_code'] is an object of type object(stdClass) .
I suppose you use json_decode before the array_chunk.
If you use json_decode($yourjson), you have to use json_decode($yourjson, true); to convert the json into array instead of stdClass.
EDIT:
Check too the keys of $c with vardump(array_keys($c)). I'm not sure $c[0] is defined.

PHP current() returns false when passing a valid array to it

i have an array with size=1 and when i try to get the current array its returns false but the array has values.
$article=getArticle($id);
if(is_array($article))
{ $article=current($article); }
the getArticle returns multidimensional array and when var_dump before current i can see the array.
If var_dump after current i get false.
if i use the code above (because the array size=1)
if(is_array($article))
{
foreach($article as $k=>$v)
{
$article=$v;
}
}
It works without any problem
Whats wrong with current?
Please help
===============EDIT========================
This is the var_dump before current
I have remove the content and summary because are large texts
array(1) {
[529]=>
array(14) {
["articles_id"]=>
string(3) "529"
["issue"]=>
string(3) "161"
["membership_type"]=>
string(1) "1"
["el"]=>
array(9) {
["title"]=>
string(23) "AUTOBIANCHI A112 ABARTH"
["url"]=>
string(23) "autobianchi-a112-abarth"
["summary"]=>
string(397) " i have remove it
"
["content"]=>
string(11580) " i have remove it too large
"
["meta_keywords"]=>
string(23) "AUTOBIANCHI,A112,ABARTH"
["meta_description"]=>
string(402) " "
["created"]=>
string(10) "1362076380"
["last_updated"]=>
string(1) "0"
["status"]=>
string(1) "1"
}
["categories_id"]=>
string(2) "12"
["authors_id"]=>
string(2) "16"
["brands_id"]=>
string(2) "36"
["models_id"]=>
string(3) "206"
["engines_id"]=>
string(3) "174"
["o-categories"]=>
array(1) {
["values"]=>
array(1) {
[12]=>
array(15) {
["categories_id"]=>
string(2) "12"
["object_id"]=>
string(1) "1"
["parent_id"]=>
string(1) "0"
["path"]=>
string(2) "12"
["handler"]=>
string(0) ""
["icon"]=>
string(0) ""
["tpl"]=>
string(12) "articles.php"
["alias"]=>
string(1) "0"
["is_nav"]=>
string(1) "1"
["pos"]=>
string(2) "10"
["depth"]=>
string(1) "0"
["cts"]=>
string(0) ""
["mts"]=>
string(0) ""
["configuration"]=>
string(0) ""
["el"]=>
array(15) {
["categories_id"]=>
string(2) "12"
["lang"]=>
string(2) "el"
["category_name"]=>
string(13) "Classic"
["sub_title"]=>
string(0) ""
["summary"]=>
string(0) ""
["image"]=>
string(0) ""
["html_code"]=>
string(0) ""
["meta_title"]=>
string(0) ""
["url"]=>
string(13) "classic"
["url_path"]=>
string(13) "classic"
["meta_keywords"]=>
string(0) ""
["meta_description"]=>
string(0) ""
["created"]=>
string(10) "1355235888"
["last_updated"]=>
string(1) "0"
["status"]=>
string(1) "1"
}
}
}
}
["o-authors"]=>
array(1) {
["values"]=>
array(1) {
[16]=>
array(4) {
["authors_id"]=>
string(2) "16"
["object_id"]=>
string(2) "26"
["image"]=>
string(0) ""
["el"]=>
array(9) {
["authors_id"]=>
string(2) "16"
["lang"]=>
string(2) "el"
["name"]=>
string(31) "Last First"
["last_name"]=>
string(10) "Last"
["first_name"]=>
string(20) "First"
["nick_name"]=>
string(0) ""
["created"]=>
string(10) "1360567827"
["last_updated"]=>
string(1) "0"
["status"]=>
string(1) "1"
}
}
}
}
["o-brands"]=>
array(1) {
["values"]=>
array(1) {
[36]=>
array(6) {
["brands_id"]=>
string(2) "36"
["object_id"]=>
string(2) "17"
["brand_name"]=>
string(11) "AUTOBIANCHI"
["created"]=>
string(10) "1363179463"
["last_updated"]=>
string(1) "0"
["status"]=>
string(1) "1"
}
}
}
["o-models"]=>
array(1) {
["values"]=>
array(1) {
[206]=>
array(7) {
["models_id"]=>
string(3) "206"
["object_id"]=>
string(2) "18"
["brands_id"]=>
string(2) "36"
["model_name"]=>
string(11) "A112 ABARTH"
["created"]=>
string(10) "1363179480"
["last_updated"]=>
string(1) "0"
["status"]=>
string(1) "1"
}
}
}
["o-engines"]=>
array(1) {
["values"]=>
array(1) {
[174]=>
array(6) {
["engines_id"]=>
string(3) "174"
["object_id"]=>
string(2) "19"
["engine"]=>
string(5) "1.050"
["created"]=>
string(10) "1363179448"
["last_updated"]=>
string(1) "0"
["status"]=>
string(1) "1"
}
}
}
}
}
Can you try
$article=getArticle($id);
if (is_array($article)) {
$article = reset($article);
}
or
$article=getArticle($id);
if (is_array($article)) {
$article = array_shift($article);
}
You can look into the documentation about reset and the documentation about array_shift.
If you copy array in getArticle() function then its internal pointer is lost.
I think this is the reason, it returns false.

print PHP value in an array

Hello I am trying to print a specific value from an array of objects. I am trying to get a value from an array name $allPhotos with a object's property of "nme"'s value.
This is what im trying:
echo $allPhotos[0]["nme"];
this is what the array looks like:
var_dump($allPhotos);
array(2) {
[0]=> object(Photo)#1 (10) {
["product"]=> array(5) {
["PKG1"]=> string(4) "6500"
["PKG2"]=> string(4) "9500"
["8x10"]=> string(4) "1500"
["5x7"]=> string(3) "750"
["4x6"]=> string(3) "300"
}
["price"]=> NULL ["sku"]=> string(1) "1"
["nme"]=> string(5) "test1"
["dir"]=> string(51) "http://"
["status"]=> string(1) "1" ["gallery"]=> string(16) "Church Directory"
["galleryCover"]=> string(1) "0"
["family"]=> string(0) ""
["familyCover"]=> string(0) ""
}
[1]=> object(Photo)#2 (10) {
["product"]=> array(5) {
["PKG1"]=> string(4) "6500"
["PKG2"]=> string(4) "9500"
["8x10"]=> string(4) "1500"
["5x7"]=> string(3) "750"
["4x6"]=> string(3) "300"
}
["price"]=> NULL
["sku"]=> string(1) "2"
["nme"]=> string(5) "test2"
["dir"]=> string(51) "http://"
["status"]=> string(1) "1"
["gallery"]=> string(16) "Church Directory"
["galleryCover"]=> string(1) "0"
["family"]=> string(0) ""
["familyCover"]=> string(0) ""
}
}
Thanks in advance!
I believe echo $allPhotos[0]->nme; should work.

Categories