array ...
Posted on
16th Feb 2014 07:03 pm by
admin
hi
Code: function formatCategories($categories, $parentId)
{
// $navCat stores all children categories
// of $parentId
$navCat = array();
// expand only the categories with the same parent id
// all other remain compact
$ids = array();
foreach ($categories as $category) {
if ($category['cat_parent_id'] == $parentId) {
$navCat[] = $category;
}
// save the ids for later use
$ids[$category['cat_id']] = $category;
}
print_r($ids[$category[0]]);
If i am printing the array using,
print_r($ids[$category[0]]);here 0 is the start key of the array(as shown in last line of codes)..OR print_r($ids[$category[12]]);
here 12 is the cat_id of a product...
I am getting notice as,Notice: Undefined offset: 0.
without out the display of expected output..
But if i use print_r($ids);
i get,
Array ( [12] => Array ( [cat_id] => 12 [cat_parent_id] => 0 [cat_name] => Cars [cat_image] => dce08605333d805106217aaab7f93b95.jpg [cat_description] => Expensive and luxurious cars ) [13] => Array ( [cat_id] => 13 [cat_parent_id] => 0 .................................etc....
And
if i use print_r($ids[$category['cat_id']]);after for each loop
i get,
Array ( [cat_id] => 17 [cat_parent_id] => 13 [cat_name] => Hunter X Hunter [cat_image] => 746e05a7a629d53bc488115a75ee35d9.jpg [cat_description] => Story about hunter and combat )
The question is why do i get notice of undefined offset after using those,print_r($ids[$category[0]]);(as shown in last line of codes)..OR print_r($ids[$category[12]]); statements instead of expected output..
could you explain this please..
thanks
No comments posted yet
Your Answer:
Login to answer
189
40
Other forums
CU&UC guide
Hi Gurus,
can anybody provide me the link for CU&UC upgrade guide
Thanks i
Generating unique numbers using php
Hi,
I need help in generating unique number using php.I tired using rand() in php.But, by using r
Mail functionality from localhost to server
Hi
I am facing problem of mail functionality.
When i tested mail functionality in my
Selecting an "empty" date formated field
How do you select an "empty" date field? I've tried the few ways I can think.
SQL> select
Finding digits in variable containing text, and IDing them
$romanstock = "http://www.remoteprice.com/data.asp?storeid=123&itemcode=456&typ
SQL Injection
In my attempts to protect my database from mySQL injection I have created another problem for myself
WELCOME SCREEN
first of all let me tell you what does my script do,
it´s a very simple query to show a e
Help to integrate whois Domain Details to website
Hi,
can i know is their any php script r methods to add domain details to my website.
Need help to identify this error please
:confused:Can anyone help me tell what this error message means? Maybe tell me where to look to fix
getting most records by count
Code: [Select]<?php
$connect = mysql_connect("localhost","dam