how can i remove whole object from the array if that has empty array inside?
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:
Fetching all attributes from the subcategories of which product belongs to.
fetching all product attributes from product attribute table
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
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 :)
**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
add a comment |
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:
Fetching all attributes from the subcategories of which product belongs to.
fetching all product attributes from product attribute table
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
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 :)
**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
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
add a comment |
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:
Fetching all attributes from the subcategories of which product belongs to.
fetching all product attributes from product attribute table
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
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 :)
**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
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:
Fetching all attributes from the subcategories of which product belongs to.
fetching all product attributes from product attribute table
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
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 :)
**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
php arrays laravel multidimensional-array
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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 foreach
ed. what this do is convert the array to a collection and filter out all object with a non empty records.
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 doingforeach($product_attributes as $item)
– Joe
Nov 14 '18 at 10:59
add a comment |
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);
}
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
|
show 2 more comments
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 foreach
ed. what this do is convert the array to a collection and filter out all object with a non empty records.
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 doingforeach($product_attributes as $item)
– Joe
Nov 14 '18 at 10:59
add a comment |
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 foreach
ed. what this do is convert the array to a collection and filter out all object with a non empty records.
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 doingforeach($product_attributes as $item)
– Joe
Nov 14 '18 at 10:59
add a comment |
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 foreach
ed. what this do is convert the array to a collection and filter out all object with a non empty records.
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 foreach
ed. what this do is convert the array to a collection and filter out all object with a non empty records.
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 doingforeach($product_attributes as $item)
– Joe
Nov 14 '18 at 10:59
add a comment |
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 doingforeach($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
add a comment |
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);
}
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
|
show 2 more comments
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);
}
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
|
show 2 more comments
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);
}
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);
}
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
|
show 2 more comments
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
|
show 2 more comments
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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