how can i remove whole object from the array if that has empty array inside?












0















What I want to achieve?



"product_attributes": [
{
"title": "Color",
"records": [
{
"attribute_name": "black",
"mpr": "100"
},
{
"attribute_name": "green",
"mpr": "200"
}
]
},
{
"title": "RAM",
"records": [
{
"attribute_name": "16GB",
"mpr": "10"
}
]
},
{
"title": "RAM",///remove this whole obeject
"records":
}
]


what I have tried: I fetch whole attributes from the DB and then compare it to product attribute and made this format now the problem is when I start traversing its comparing result from all attribute which creates an empty object every time my if() condition fails.



how can I remove empty object having empty records array and reindex my final array?



here is my code :



$allattributes = DB::table('product_attributes')->where('subcategory_id', $product->subcat_id)->get(['attribute_title']);

$valuesnew = DB::table('current_product_attribute_values')->where('product_id', $product->id)->get();

$emptybool=false;
// checking for empty attributes

if ($valuesnew->count() > 0) {




// first foreach for 3 value
foreach ($allattributes as $name) {

//echo $name->attribute_title;

$boo = false;


// 40 record loop

$records = array();
foreach ($valuesnew as $compare) {


// if attibute title are same
if ($compare->attribute_title == $name->attribute_title) {

if ($boo == false) {

$titledata = $name->attribute_title;

$holddata['title'] = $titledata;


$boo = true;
}

$records = array("attribute_name" => $compare->attribute_value, "mpr" => $compare->attribute_mrp);
}

}


$holddata['records'] = $records;
$final = $holddata;


}
} else {
$final = array();
}


what i have tried:



foreach($final as $k=>$arr){ 

//$final=array_filter($arr,'count');
if(array_filter($arr,'count') || array_values(array_filter($arr))){
unset($arr[$i]);
}

$i++;

}

print_r($final);//failed


TEST CASE:




  1. Fetching all attributes from the subcategories of which product belongs to.


  2. fetching all product attributes from product attribute table


  3. then comparing the title of all attributes with product attributes when found the same record I have put this in inside the array. so I achieve color=>red, black this type of structure instead of color=>red, color=>black


  4. now the test case is when all attributes have 4 attributes color, size, ram, processor, and product having only two color and ram at this case my loop give me empty record as with the last title I want to remove that object having an empty record.



thanks in advance :)



all attribute table product attribute table



**NEW TRY: **



foreach($final as $k=>$arr){ 


foreach($arr as $key=>$value){
$count=count($value);
if($count==0){
echo '<pre>';
echo ' am empty object remove me ';
'<br>';
unset($arr[$index]);//failed how can i remove this whole object from the main array


}
}









share|improve this question

























  • do you still want to use Query Builder? if you're open to suggestions, I think writing models are a better way

    – Joe
    Nov 14 '18 at 9:16











  • yes i can use that too if you have suggestion about that please share

    – Jagdish Sharma
    Nov 14 '18 at 9:37
















0















What I want to achieve?



"product_attributes": [
{
"title": "Color",
"records": [
{
"attribute_name": "black",
"mpr": "100"
},
{
"attribute_name": "green",
"mpr": "200"
}
]
},
{
"title": "RAM",
"records": [
{
"attribute_name": "16GB",
"mpr": "10"
}
]
},
{
"title": "RAM",///remove this whole obeject
"records":
}
]


what I have tried: I fetch whole attributes from the DB and then compare it to product attribute and made this format now the problem is when I start traversing its comparing result from all attribute which creates an empty object every time my if() condition fails.



how can I remove empty object having empty records array and reindex my final array?



here is my code :



$allattributes = DB::table('product_attributes')->where('subcategory_id', $product->subcat_id)->get(['attribute_title']);

$valuesnew = DB::table('current_product_attribute_values')->where('product_id', $product->id)->get();

$emptybool=false;
// checking for empty attributes

if ($valuesnew->count() > 0) {




// first foreach for 3 value
foreach ($allattributes as $name) {

//echo $name->attribute_title;

$boo = false;


// 40 record loop

$records = array();
foreach ($valuesnew as $compare) {


// if attibute title are same
if ($compare->attribute_title == $name->attribute_title) {

if ($boo == false) {

$titledata = $name->attribute_title;

$holddata['title'] = $titledata;


$boo = true;
}

$records = array("attribute_name" => $compare->attribute_value, "mpr" => $compare->attribute_mrp);
}

}


$holddata['records'] = $records;
$final = $holddata;


}
} else {
$final = array();
}


what i have tried:



foreach($final as $k=>$arr){ 

//$final=array_filter($arr,'count');
if(array_filter($arr,'count') || array_values(array_filter($arr))){
unset($arr[$i]);
}

$i++;

}

print_r($final);//failed


TEST CASE:




  1. Fetching all attributes from the subcategories of which product belongs to.


  2. fetching all product attributes from product attribute table


  3. then comparing the title of all attributes with product attributes when found the same record I have put this in inside the array. so I achieve color=>red, black this type of structure instead of color=>red, color=>black


  4. now the test case is when all attributes have 4 attributes color, size, ram, processor, and product having only two color and ram at this case my loop give me empty record as with the last title I want to remove that object having an empty record.



thanks in advance :)



all attribute table product attribute table



**NEW TRY: **



foreach($final as $k=>$arr){ 


foreach($arr as $key=>$value){
$count=count($value);
if($count==0){
echo '<pre>';
echo ' am empty object remove me ';
'<br>';
unset($arr[$index]);//failed how can i remove this whole object from the main array


}
}









share|improve this question

























  • do you still want to use Query Builder? if you're open to suggestions, I think writing models are a better way

    – Joe
    Nov 14 '18 at 9:16











  • yes i can use that too if you have suggestion about that please share

    – Jagdish Sharma
    Nov 14 '18 at 9:37














0












0








0








What I want to achieve?



"product_attributes": [
{
"title": "Color",
"records": [
{
"attribute_name": "black",
"mpr": "100"
},
{
"attribute_name": "green",
"mpr": "200"
}
]
},
{
"title": "RAM",
"records": [
{
"attribute_name": "16GB",
"mpr": "10"
}
]
},
{
"title": "RAM",///remove this whole obeject
"records":
}
]


what I have tried: I fetch whole attributes from the DB and then compare it to product attribute and made this format now the problem is when I start traversing its comparing result from all attribute which creates an empty object every time my if() condition fails.



how can I remove empty object having empty records array and reindex my final array?



here is my code :



$allattributes = DB::table('product_attributes')->where('subcategory_id', $product->subcat_id)->get(['attribute_title']);

$valuesnew = DB::table('current_product_attribute_values')->where('product_id', $product->id)->get();

$emptybool=false;
// checking for empty attributes

if ($valuesnew->count() > 0) {




// first foreach for 3 value
foreach ($allattributes as $name) {

//echo $name->attribute_title;

$boo = false;


// 40 record loop

$records = array();
foreach ($valuesnew as $compare) {


// if attibute title are same
if ($compare->attribute_title == $name->attribute_title) {

if ($boo == false) {

$titledata = $name->attribute_title;

$holddata['title'] = $titledata;


$boo = true;
}

$records = array("attribute_name" => $compare->attribute_value, "mpr" => $compare->attribute_mrp);
}

}


$holddata['records'] = $records;
$final = $holddata;


}
} else {
$final = array();
}


what i have tried:



foreach($final as $k=>$arr){ 

//$final=array_filter($arr,'count');
if(array_filter($arr,'count') || array_values(array_filter($arr))){
unset($arr[$i]);
}

$i++;

}

print_r($final);//failed


TEST CASE:




  1. Fetching all attributes from the subcategories of which product belongs to.


  2. fetching all product attributes from product attribute table


  3. then comparing the title of all attributes with product attributes when found the same record I have put this in inside the array. so I achieve color=>red, black this type of structure instead of color=>red, color=>black


  4. now the test case is when all attributes have 4 attributes color, size, ram, processor, and product having only two color and ram at this case my loop give me empty record as with the last title I want to remove that object having an empty record.



thanks in advance :)



all attribute table product attribute table



**NEW TRY: **



foreach($final as $k=>$arr){ 


foreach($arr as $key=>$value){
$count=count($value);
if($count==0){
echo '<pre>';
echo ' am empty object remove me ';
'<br>';
unset($arr[$index]);//failed how can i remove this whole object from the main array


}
}









share|improve this question
















What I want to achieve?



"product_attributes": [
{
"title": "Color",
"records": [
{
"attribute_name": "black",
"mpr": "100"
},
{
"attribute_name": "green",
"mpr": "200"
}
]
},
{
"title": "RAM",
"records": [
{
"attribute_name": "16GB",
"mpr": "10"
}
]
},
{
"title": "RAM",///remove this whole obeject
"records":
}
]


what I have tried: I fetch whole attributes from the DB and then compare it to product attribute and made this format now the problem is when I start traversing its comparing result from all attribute which creates an empty object every time my if() condition fails.



how can I remove empty object having empty records array and reindex my final array?



here is my code :



$allattributes = DB::table('product_attributes')->where('subcategory_id', $product->subcat_id)->get(['attribute_title']);

$valuesnew = DB::table('current_product_attribute_values')->where('product_id', $product->id)->get();

$emptybool=false;
// checking for empty attributes

if ($valuesnew->count() > 0) {




// first foreach for 3 value
foreach ($allattributes as $name) {

//echo $name->attribute_title;

$boo = false;


// 40 record loop

$records = array();
foreach ($valuesnew as $compare) {


// if attibute title are same
if ($compare->attribute_title == $name->attribute_title) {

if ($boo == false) {

$titledata = $name->attribute_title;

$holddata['title'] = $titledata;


$boo = true;
}

$records = array("attribute_name" => $compare->attribute_value, "mpr" => $compare->attribute_mrp);
}

}


$holddata['records'] = $records;
$final = $holddata;


}
} else {
$final = array();
}


what i have tried:



foreach($final as $k=>$arr){ 

//$final=array_filter($arr,'count');
if(array_filter($arr,'count') || array_values(array_filter($arr))){
unset($arr[$i]);
}

$i++;

}

print_r($final);//failed


TEST CASE:




  1. Fetching all attributes from the subcategories of which product belongs to.


  2. fetching all product attributes from product attribute table


  3. then comparing the title of all attributes with product attributes when found the same record I have put this in inside the array. so I achieve color=>red, black this type of structure instead of color=>red, color=>black


  4. now the test case is when all attributes have 4 attributes color, size, ram, processor, and product having only two color and ram at this case my loop give me empty record as with the last title I want to remove that object having an empty record.



thanks in advance :)



all attribute table product attribute table



**NEW TRY: **



foreach($final as $k=>$arr){ 


foreach($arr as $key=>$value){
$count=count($value);
if($count==0){
echo '<pre>';
echo ' am empty object remove me ';
'<br>';
unset($arr[$index]);//failed how can i remove this whole object from the main array


}
}






php arrays laravel multidimensional-array






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 10:03







Jagdish Sharma

















asked Nov 14 '18 at 8:03









Jagdish SharmaJagdish Sharma

18113




18113













  • do you still want to use Query Builder? if you're open to suggestions, I think writing models are a better way

    – Joe
    Nov 14 '18 at 9:16











  • yes i can use that too if you have suggestion about that please share

    – Jagdish Sharma
    Nov 14 '18 at 9:37



















  • do you still want to use Query Builder? if you're open to suggestions, I think writing models are a better way

    – Joe
    Nov 14 '18 at 9:16











  • yes i can use that too if you have suggestion about that please share

    – Jagdish Sharma
    Nov 14 '18 at 9:37

















do you still want to use Query Builder? if you're open to suggestions, I think writing models are a better way

– Joe
Nov 14 '18 at 9:16





do you still want to use Query Builder? if you're open to suggestions, I think writing models are a better way

– Joe
Nov 14 '18 at 9:16













yes i can use that too if you have suggestion about that please share

– Jagdish Sharma
Nov 14 '18 at 9:37





yes i can use that too if you have suggestion about that please share

– Jagdish Sharma
Nov 14 '18 at 9:37












2 Answers
2






active

oldest

votes


















1














you could try to filter the collection for rows the doesn't have record.



$withRecordsOnly = collect($product_attributes)->filter(function ($item) {
return !empty($item->records);
});


$product_attributes is the same array you have foreached. what this do is convert the array to a collection and filter out all object with a non empty records.






share|improve this answer


























  • the test is not from database it's like this am editing my question for showing my test case wait..and thanx for reply @Joe

    – Jagdish Sharma
    Nov 14 '18 at 8:24











  • i have updated my answer, using the same array that you echoed above, you need to convert it to a collection and filter them out

    – Joe
    Nov 14 '18 at 9:03











  • ok so make my final array as a collection then filtering records for the empty object. But what is $item here is can u explain code more so i can understand

    – Jagdish Sharma
    Nov 14 '18 at 9:39











  • the parameter $item is the single element of the collection, and it iterate and return only non-empty $item->records. you could name it anyway you want. it's like doing foreach($product_attributes as $item)

    – Joe
    Nov 14 '18 at 10:59



















0














Someone already posted using filter its definitely the solution for you. You don't need to have get the data from the database to use a collection.



collect($productAttributesArray).filter(function($product){
return !empty($product->records);
}





share|improve this answer
























  • thanks for your reply Mike Miller I agree with u but here the problem is database doesn't have empty value

    – Jagdish Sharma
    Nov 14 '18 at 8:52











  • I have added my database table screenshot .

    – Jagdish Sharma
    Nov 14 '18 at 8:56











  • I dont follow. You mean the records array is not empty?

    – Mike Miller
    Nov 14 '18 at 9:14











  • yes, its the combination I have checked for example a Samsung phone has attribute color and ram only and mobile subcategories have color ram processor size etc all so when I checked for the combination of the title (which is color, ram ) if match I put them in one object.

    – Jagdish Sharma
    Nov 14 '18 at 9:42











  • I think you are approaching this the wrong way. I don't really understand what you said but sounds like your data model is wrong. If you want to achieve the array structure shown at the top of your post you should model your DB schema like that OR use a NoSQL database

    – Mike Miller
    Nov 14 '18 at 9:45











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295492%2fhow-can-i-remove-whole-object-from-the-array-if-that-has-empty-array-inside%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














you could try to filter the collection for rows the doesn't have record.



$withRecordsOnly = collect($product_attributes)->filter(function ($item) {
return !empty($item->records);
});


$product_attributes is the same array you have foreached. what this do is convert the array to a collection and filter out all object with a non empty records.






share|improve this answer


























  • the test is not from database it's like this am editing my question for showing my test case wait..and thanx for reply @Joe

    – Jagdish Sharma
    Nov 14 '18 at 8:24











  • i have updated my answer, using the same array that you echoed above, you need to convert it to a collection and filter them out

    – Joe
    Nov 14 '18 at 9:03











  • ok so make my final array as a collection then filtering records for the empty object. But what is $item here is can u explain code more so i can understand

    – Jagdish Sharma
    Nov 14 '18 at 9:39











  • the parameter $item is the single element of the collection, and it iterate and return only non-empty $item->records. you could name it anyway you want. it's like doing foreach($product_attributes as $item)

    – Joe
    Nov 14 '18 at 10:59
















1














you could try to filter the collection for rows the doesn't have record.



$withRecordsOnly = collect($product_attributes)->filter(function ($item) {
return !empty($item->records);
});


$product_attributes is the same array you have foreached. what this do is convert the array to a collection and filter out all object with a non empty records.






share|improve this answer


























  • the test is not from database it's like this am editing my question for showing my test case wait..and thanx for reply @Joe

    – Jagdish Sharma
    Nov 14 '18 at 8:24











  • i have updated my answer, using the same array that you echoed above, you need to convert it to a collection and filter them out

    – Joe
    Nov 14 '18 at 9:03











  • ok so make my final array as a collection then filtering records for the empty object. But what is $item here is can u explain code more so i can understand

    – Jagdish Sharma
    Nov 14 '18 at 9:39











  • the parameter $item is the single element of the collection, and it iterate and return only non-empty $item->records. you could name it anyway you want. it's like doing foreach($product_attributes as $item)

    – Joe
    Nov 14 '18 at 10:59














1












1








1







you could try to filter the collection for rows the doesn't have record.



$withRecordsOnly = collect($product_attributes)->filter(function ($item) {
return !empty($item->records);
});


$product_attributes is the same array you have foreached. what this do is convert the array to a collection and filter out all object with a non empty records.






share|improve this answer















you could try to filter the collection for rows the doesn't have record.



$withRecordsOnly = collect($product_attributes)->filter(function ($item) {
return !empty($item->records);
});


$product_attributes is the same array you have foreached. what this do is convert the array to a collection and filter out all object with a non empty records.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 9:02

























answered Nov 14 '18 at 8:14









JoeJoe

384217




384217













  • the test is not from database it's like this am editing my question for showing my test case wait..and thanx for reply @Joe

    – Jagdish Sharma
    Nov 14 '18 at 8:24











  • i have updated my answer, using the same array that you echoed above, you need to convert it to a collection and filter them out

    – Joe
    Nov 14 '18 at 9:03











  • ok so make my final array as a collection then filtering records for the empty object. But what is $item here is can u explain code more so i can understand

    – Jagdish Sharma
    Nov 14 '18 at 9:39











  • the parameter $item is the single element of the collection, and it iterate and return only non-empty $item->records. you could name it anyway you want. it's like doing foreach($product_attributes as $item)

    – Joe
    Nov 14 '18 at 10:59



















  • the test is not from database it's like this am editing my question for showing my test case wait..and thanx for reply @Joe

    – Jagdish Sharma
    Nov 14 '18 at 8:24











  • i have updated my answer, using the same array that you echoed above, you need to convert it to a collection and filter them out

    – Joe
    Nov 14 '18 at 9:03











  • ok so make my final array as a collection then filtering records for the empty object. But what is $item here is can u explain code more so i can understand

    – Jagdish Sharma
    Nov 14 '18 at 9:39











  • the parameter $item is the single element of the collection, and it iterate and return only non-empty $item->records. you could name it anyway you want. it's like doing foreach($product_attributes as $item)

    – Joe
    Nov 14 '18 at 10:59

















the test is not from database it's like this am editing my question for showing my test case wait..and thanx for reply @Joe

– Jagdish Sharma
Nov 14 '18 at 8:24





the test is not from database it's like this am editing my question for showing my test case wait..and thanx for reply @Joe

– Jagdish Sharma
Nov 14 '18 at 8:24













i have updated my answer, using the same array that you echoed above, you need to convert it to a collection and filter them out

– Joe
Nov 14 '18 at 9:03





i have updated my answer, using the same array that you echoed above, you need to convert it to a collection and filter them out

– Joe
Nov 14 '18 at 9:03













ok so make my final array as a collection then filtering records for the empty object. But what is $item here is can u explain code more so i can understand

– Jagdish Sharma
Nov 14 '18 at 9:39





ok so make my final array as a collection then filtering records for the empty object. But what is $item here is can u explain code more so i can understand

– Jagdish Sharma
Nov 14 '18 at 9:39













the parameter $item is the single element of the collection, and it iterate and return only non-empty $item->records. you could name it anyway you want. it's like doing foreach($product_attributes as $item)

– Joe
Nov 14 '18 at 10:59





the parameter $item is the single element of the collection, and it iterate and return only non-empty $item->records. you could name it anyway you want. it's like doing foreach($product_attributes as $item)

– Joe
Nov 14 '18 at 10:59













0














Someone already posted using filter its definitely the solution for you. You don't need to have get the data from the database to use a collection.



collect($productAttributesArray).filter(function($product){
return !empty($product->records);
}





share|improve this answer
























  • thanks for your reply Mike Miller I agree with u but here the problem is database doesn't have empty value

    – Jagdish Sharma
    Nov 14 '18 at 8:52











  • I have added my database table screenshot .

    – Jagdish Sharma
    Nov 14 '18 at 8:56











  • I dont follow. You mean the records array is not empty?

    – Mike Miller
    Nov 14 '18 at 9:14











  • yes, its the combination I have checked for example a Samsung phone has attribute color and ram only and mobile subcategories have color ram processor size etc all so when I checked for the combination of the title (which is color, ram ) if match I put them in one object.

    – Jagdish Sharma
    Nov 14 '18 at 9:42











  • I think you are approaching this the wrong way. I don't really understand what you said but sounds like your data model is wrong. If you want to achieve the array structure shown at the top of your post you should model your DB schema like that OR use a NoSQL database

    – Mike Miller
    Nov 14 '18 at 9:45
















0














Someone already posted using filter its definitely the solution for you. You don't need to have get the data from the database to use a collection.



collect($productAttributesArray).filter(function($product){
return !empty($product->records);
}





share|improve this answer
























  • thanks for your reply Mike Miller I agree with u but here the problem is database doesn't have empty value

    – Jagdish Sharma
    Nov 14 '18 at 8:52











  • I have added my database table screenshot .

    – Jagdish Sharma
    Nov 14 '18 at 8:56











  • I dont follow. You mean the records array is not empty?

    – Mike Miller
    Nov 14 '18 at 9:14











  • yes, its the combination I have checked for example a Samsung phone has attribute color and ram only and mobile subcategories have color ram processor size etc all so when I checked for the combination of the title (which is color, ram ) if match I put them in one object.

    – Jagdish Sharma
    Nov 14 '18 at 9:42











  • I think you are approaching this the wrong way. I don't really understand what you said but sounds like your data model is wrong. If you want to achieve the array structure shown at the top of your post you should model your DB schema like that OR use a NoSQL database

    – Mike Miller
    Nov 14 '18 at 9:45














0












0








0







Someone already posted using filter its definitely the solution for you. You don't need to have get the data from the database to use a collection.



collect($productAttributesArray).filter(function($product){
return !empty($product->records);
}





share|improve this answer













Someone already posted using filter its definitely the solution for you. You don't need to have get the data from the database to use a collection.



collect($productAttributesArray).filter(function($product){
return !empty($product->records);
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 8:47









Mike MillerMike Miller

2,07611220




2,07611220













  • thanks for your reply Mike Miller I agree with u but here the problem is database doesn't have empty value

    – Jagdish Sharma
    Nov 14 '18 at 8:52











  • I have added my database table screenshot .

    – Jagdish Sharma
    Nov 14 '18 at 8:56











  • I dont follow. You mean the records array is not empty?

    – Mike Miller
    Nov 14 '18 at 9:14











  • yes, its the combination I have checked for example a Samsung phone has attribute color and ram only and mobile subcategories have color ram processor size etc all so when I checked for the combination of the title (which is color, ram ) if match I put them in one object.

    – Jagdish Sharma
    Nov 14 '18 at 9:42











  • I think you are approaching this the wrong way. I don't really understand what you said but sounds like your data model is wrong. If you want to achieve the array structure shown at the top of your post you should model your DB schema like that OR use a NoSQL database

    – Mike Miller
    Nov 14 '18 at 9:45



















  • thanks for your reply Mike Miller I agree with u but here the problem is database doesn't have empty value

    – Jagdish Sharma
    Nov 14 '18 at 8:52











  • I have added my database table screenshot .

    – Jagdish Sharma
    Nov 14 '18 at 8:56











  • I dont follow. You mean the records array is not empty?

    – Mike Miller
    Nov 14 '18 at 9:14











  • yes, its the combination I have checked for example a Samsung phone has attribute color and ram only and mobile subcategories have color ram processor size etc all so when I checked for the combination of the title (which is color, ram ) if match I put them in one object.

    – Jagdish Sharma
    Nov 14 '18 at 9:42











  • I think you are approaching this the wrong way. I don't really understand what you said but sounds like your data model is wrong. If you want to achieve the array structure shown at the top of your post you should model your DB schema like that OR use a NoSQL database

    – Mike Miller
    Nov 14 '18 at 9:45

















thanks for your reply Mike Miller I agree with u but here the problem is database doesn't have empty value

– Jagdish Sharma
Nov 14 '18 at 8:52





thanks for your reply Mike Miller I agree with u but here the problem is database doesn't have empty value

– Jagdish Sharma
Nov 14 '18 at 8:52













I have added my database table screenshot .

– Jagdish Sharma
Nov 14 '18 at 8:56





I have added my database table screenshot .

– Jagdish Sharma
Nov 14 '18 at 8:56













I dont follow. You mean the records array is not empty?

– Mike Miller
Nov 14 '18 at 9:14





I dont follow. You mean the records array is not empty?

– Mike Miller
Nov 14 '18 at 9:14













yes, its the combination I have checked for example a Samsung phone has attribute color and ram only and mobile subcategories have color ram processor size etc all so when I checked for the combination of the title (which is color, ram ) if match I put them in one object.

– Jagdish Sharma
Nov 14 '18 at 9:42





yes, its the combination I have checked for example a Samsung phone has attribute color and ram only and mobile subcategories have color ram processor size etc all so when I checked for the combination of the title (which is color, ram ) if match I put them in one object.

– Jagdish Sharma
Nov 14 '18 at 9:42













I think you are approaching this the wrong way. I don't really understand what you said but sounds like your data model is wrong. If you want to achieve the array structure shown at the top of your post you should model your DB schema like that OR use a NoSQL database

– Mike Miller
Nov 14 '18 at 9:45





I think you are approaching this the wrong way. I don't really understand what you said but sounds like your data model is wrong. If you want to achieve the array structure shown at the top of your post you should model your DB schema like that OR use a NoSQL database

– Mike Miller
Nov 14 '18 at 9:45


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295492%2fhow-can-i-remove-whole-object-from-the-array-if-that-has-empty-array-inside%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine