Padding data for sometimes missing object index












0















I have an array where I'm looping on an object



foreach ($product->info->details as $details) {

$skuItem = $details->dtl1;
$skuItem = $details->dtl2;
$skuItem = $details->dtl3;

}


The object it loops on is structured this way



"details": {
"1": {
"dtl1": "123",
"dtl2": "TEst",
"dtl3": "123"
},
"2": {
"dtl1": "12",
"dtl2": "Test",
"dtl3": "153"
}
},


The thing is, it can only have up to 2 of those sets but sometimes it has only one.



Is there a way to accomodate in my foreach loop so that if there is only one then I can basically 'dummy up' a second set with all zeroes? I'm mapping this to a file and need to make sure I'm at least always mapping all 6 values



So if the object looks like



"details": {
"1": {
"dtl1": "123",
"dtl2": "TEst",
"dtl3": "123"
}


I would want to create my array like



0 => "123",
1 => "TEst",
2 => "123"
3 => "0",
4 => "0",
5 => "0"









share|improve this question




















  • 1





    foreach($details as $key => $value) { ... }

    – Sammitch
    Jan 18 at 18:54











  • but if an item only has the key of "1", how can I still create a hypothetical "2" key with all zeroes

    – Whisou138
    Jan 18 at 18:55
















0















I have an array where I'm looping on an object



foreach ($product->info->details as $details) {

$skuItem = $details->dtl1;
$skuItem = $details->dtl2;
$skuItem = $details->dtl3;

}


The object it loops on is structured this way



"details": {
"1": {
"dtl1": "123",
"dtl2": "TEst",
"dtl3": "123"
},
"2": {
"dtl1": "12",
"dtl2": "Test",
"dtl3": "153"
}
},


The thing is, it can only have up to 2 of those sets but sometimes it has only one.



Is there a way to accomodate in my foreach loop so that if there is only one then I can basically 'dummy up' a second set with all zeroes? I'm mapping this to a file and need to make sure I'm at least always mapping all 6 values



So if the object looks like



"details": {
"1": {
"dtl1": "123",
"dtl2": "TEst",
"dtl3": "123"
}


I would want to create my array like



0 => "123",
1 => "TEst",
2 => "123"
3 => "0",
4 => "0",
5 => "0"









share|improve this question




















  • 1





    foreach($details as $key => $value) { ... }

    – Sammitch
    Jan 18 at 18:54











  • but if an item only has the key of "1", how can I still create a hypothetical "2" key with all zeroes

    – Whisou138
    Jan 18 at 18:55














0












0








0








I have an array where I'm looping on an object



foreach ($product->info->details as $details) {

$skuItem = $details->dtl1;
$skuItem = $details->dtl2;
$skuItem = $details->dtl3;

}


The object it loops on is structured this way



"details": {
"1": {
"dtl1": "123",
"dtl2": "TEst",
"dtl3": "123"
},
"2": {
"dtl1": "12",
"dtl2": "Test",
"dtl3": "153"
}
},


The thing is, it can only have up to 2 of those sets but sometimes it has only one.



Is there a way to accomodate in my foreach loop so that if there is only one then I can basically 'dummy up' a second set with all zeroes? I'm mapping this to a file and need to make sure I'm at least always mapping all 6 values



So if the object looks like



"details": {
"1": {
"dtl1": "123",
"dtl2": "TEst",
"dtl3": "123"
}


I would want to create my array like



0 => "123",
1 => "TEst",
2 => "123"
3 => "0",
4 => "0",
5 => "0"









share|improve this question
















I have an array where I'm looping on an object



foreach ($product->info->details as $details) {

$skuItem = $details->dtl1;
$skuItem = $details->dtl2;
$skuItem = $details->dtl3;

}


The object it loops on is structured this way



"details": {
"1": {
"dtl1": "123",
"dtl2": "TEst",
"dtl3": "123"
},
"2": {
"dtl1": "12",
"dtl2": "Test",
"dtl3": "153"
}
},


The thing is, it can only have up to 2 of those sets but sometimes it has only one.



Is there a way to accomodate in my foreach loop so that if there is only one then I can basically 'dummy up' a second set with all zeroes? I'm mapping this to a file and need to make sure I'm at least always mapping all 6 values



So if the object looks like



"details": {
"1": {
"dtl1": "123",
"dtl2": "TEst",
"dtl3": "123"
}


I would want to create my array like



0 => "123",
1 => "TEst",
2 => "123"
3 => "0",
4 => "0",
5 => "0"






php arrays object foreach






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 18 at 18:55







Whisou138

















asked Jan 18 at 18:51









Whisou138Whisou138

1729




1729








  • 1





    foreach($details as $key => $value) { ... }

    – Sammitch
    Jan 18 at 18:54











  • but if an item only has the key of "1", how can I still create a hypothetical "2" key with all zeroes

    – Whisou138
    Jan 18 at 18:55














  • 1





    foreach($details as $key => $value) { ... }

    – Sammitch
    Jan 18 at 18:54











  • but if an item only has the key of "1", how can I still create a hypothetical "2" key with all zeroes

    – Whisou138
    Jan 18 at 18:55








1




1





foreach($details as $key => $value) { ... }

– Sammitch
Jan 18 at 18:54





foreach($details as $key => $value) { ... }

– Sammitch
Jan 18 at 18:54













but if an item only has the key of "1", how can I still create a hypothetical "2" key with all zeroes

– Whisou138
Jan 18 at 18:55





but if an item only has the key of "1", how can I still create a hypothetical "2" key with all zeroes

– Whisou138
Jan 18 at 18:55












2 Answers
2






active

oldest

votes


















3














After the foreach, you can pad your array with zero:



foreach ($product->info->details as $details) {
$skuItem = $details->dtl1;
$skuItem = $details->dtl2;
$skuItem = $details->dtl3;
}


Array now contains:



0 => "123"
1 => "TEst"
2 => "123"


Now run:



$skuItem = array_pad($skuItem, 6, 0);


This will add zeros to the end of the array until you get 6 items in it, so the array now contains:



0 => '123'
1 => 'TEst'
2 => '123'
3 => 0
4 => 0
5 => 0


If you want string zero instead, then just pass that as the 3rd arg:



$skuItem = array_pad($skuItem, 6, '0');


Yields:



0 => '123'
1 => 'TEst'
2 => '123'
3 => '0'
4 => '0'
5 => '0'





share|improve this answer


























  • I'm not sure if that's exactly what I was getting at, sorry for any confusion. Some times the details object only has an element with the key of "1", but I would still want to create data in the array with one of "2"

    – Whisou138
    Jan 18 at 18:56











  • @Whisou138 this looks like it would produce the output you showed in the edit you just made to your question

    – Don't Panic
    Jan 18 at 18:58






  • 1





    Right. If your original object only had one item and you created an array with 3 values, then the pad would expand that to 6. If your original object had two items and you created an array with 6 values, then the pad would do nothing.

    – Alex Howansky
    Jan 18 at 18:58













  • Ok so I think that makes sense but I found an issue. When I run it, it doesn't fill because I've already put things in the array before this so there's always 6 items basically. Is there a way to check in the loop so that if there's only one then add another set?

    – Whisou138
    Jan 18 at 19:21











  • So there's already 7 values in the skuItem array by the time it gets to this foreach loop

    – Whisou138
    Jan 18 at 19:22



















0














You can create a template of what you want and replace with what you create in the loop:



$skuItem = array_replace(array_fill(0, 6, 0), $skuItem);


array_pad is probably better for this trivial example, but consider if you have a variety of values:



$temp = array('x', 'y', 'z', 'x', 'y', 'z');
$skuItem = array_replace($temp, $skuItem);


Or:



$temp = array('x', 'y', 'z');
if(count($skuItem) != 6) {
$skuItem = array_merge($skuItem, $temp);
}





share|improve this answer


























  • is there a way in that if statement to check if the foreach on details contained one set or two instead?

    – Whisou138
    Jan 18 at 19:21











  • Before the loop just check count($product->info->details). But since you show 3 in each object then if there are 3 in result array then there was 1 if there are 6 then there are 2, etc...

    – AbraCadaver
    Jan 18 at 19:24













  • Can you kind of show how I would use the count to dictate whether or not to add zeroes though?

    – Whisou138
    Jan 18 at 19:30











  • You'll need to be more specific. My first code replaces six 0s with what you generate in the loop. If loop generates three values then they replace the first three 0s, if loop generates six values then all 0s are replaced by what you generated in the loop. You will always have 6 in result.

    – AbraCadaver
    Jan 18 at 19:35













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%2f54259880%2fpadding-data-for-sometimes-missing-object-index%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









3














After the foreach, you can pad your array with zero:



foreach ($product->info->details as $details) {
$skuItem = $details->dtl1;
$skuItem = $details->dtl2;
$skuItem = $details->dtl3;
}


Array now contains:



0 => "123"
1 => "TEst"
2 => "123"


Now run:



$skuItem = array_pad($skuItem, 6, 0);


This will add zeros to the end of the array until you get 6 items in it, so the array now contains:



0 => '123'
1 => 'TEst'
2 => '123'
3 => 0
4 => 0
5 => 0


If you want string zero instead, then just pass that as the 3rd arg:



$skuItem = array_pad($skuItem, 6, '0');


Yields:



0 => '123'
1 => 'TEst'
2 => '123'
3 => '0'
4 => '0'
5 => '0'





share|improve this answer


























  • I'm not sure if that's exactly what I was getting at, sorry for any confusion. Some times the details object only has an element with the key of "1", but I would still want to create data in the array with one of "2"

    – Whisou138
    Jan 18 at 18:56











  • @Whisou138 this looks like it would produce the output you showed in the edit you just made to your question

    – Don't Panic
    Jan 18 at 18:58






  • 1





    Right. If your original object only had one item and you created an array with 3 values, then the pad would expand that to 6. If your original object had two items and you created an array with 6 values, then the pad would do nothing.

    – Alex Howansky
    Jan 18 at 18:58













  • Ok so I think that makes sense but I found an issue. When I run it, it doesn't fill because I've already put things in the array before this so there's always 6 items basically. Is there a way to check in the loop so that if there's only one then add another set?

    – Whisou138
    Jan 18 at 19:21











  • So there's already 7 values in the skuItem array by the time it gets to this foreach loop

    – Whisou138
    Jan 18 at 19:22
















3














After the foreach, you can pad your array with zero:



foreach ($product->info->details as $details) {
$skuItem = $details->dtl1;
$skuItem = $details->dtl2;
$skuItem = $details->dtl3;
}


Array now contains:



0 => "123"
1 => "TEst"
2 => "123"


Now run:



$skuItem = array_pad($skuItem, 6, 0);


This will add zeros to the end of the array until you get 6 items in it, so the array now contains:



0 => '123'
1 => 'TEst'
2 => '123'
3 => 0
4 => 0
5 => 0


If you want string zero instead, then just pass that as the 3rd arg:



$skuItem = array_pad($skuItem, 6, '0');


Yields:



0 => '123'
1 => 'TEst'
2 => '123'
3 => '0'
4 => '0'
5 => '0'





share|improve this answer


























  • I'm not sure if that's exactly what I was getting at, sorry for any confusion. Some times the details object only has an element with the key of "1", but I would still want to create data in the array with one of "2"

    – Whisou138
    Jan 18 at 18:56











  • @Whisou138 this looks like it would produce the output you showed in the edit you just made to your question

    – Don't Panic
    Jan 18 at 18:58






  • 1





    Right. If your original object only had one item and you created an array with 3 values, then the pad would expand that to 6. If your original object had two items and you created an array with 6 values, then the pad would do nothing.

    – Alex Howansky
    Jan 18 at 18:58













  • Ok so I think that makes sense but I found an issue. When I run it, it doesn't fill because I've already put things in the array before this so there's always 6 items basically. Is there a way to check in the loop so that if there's only one then add another set?

    – Whisou138
    Jan 18 at 19:21











  • So there's already 7 values in the skuItem array by the time it gets to this foreach loop

    – Whisou138
    Jan 18 at 19:22














3












3








3







After the foreach, you can pad your array with zero:



foreach ($product->info->details as $details) {
$skuItem = $details->dtl1;
$skuItem = $details->dtl2;
$skuItem = $details->dtl3;
}


Array now contains:



0 => "123"
1 => "TEst"
2 => "123"


Now run:



$skuItem = array_pad($skuItem, 6, 0);


This will add zeros to the end of the array until you get 6 items in it, so the array now contains:



0 => '123'
1 => 'TEst'
2 => '123'
3 => 0
4 => 0
5 => 0


If you want string zero instead, then just pass that as the 3rd arg:



$skuItem = array_pad($skuItem, 6, '0');


Yields:



0 => '123'
1 => 'TEst'
2 => '123'
3 => '0'
4 => '0'
5 => '0'





share|improve this answer















After the foreach, you can pad your array with zero:



foreach ($product->info->details as $details) {
$skuItem = $details->dtl1;
$skuItem = $details->dtl2;
$skuItem = $details->dtl3;
}


Array now contains:



0 => "123"
1 => "TEst"
2 => "123"


Now run:



$skuItem = array_pad($skuItem, 6, 0);


This will add zeros to the end of the array until you get 6 items in it, so the array now contains:



0 => '123'
1 => 'TEst'
2 => '123'
3 => 0
4 => 0
5 => 0


If you want string zero instead, then just pass that as the 3rd arg:



$skuItem = array_pad($skuItem, 6, '0');


Yields:



0 => '123'
1 => 'TEst'
2 => '123'
3 => '0'
4 => '0'
5 => '0'






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 18 at 19:06

























answered Jan 18 at 18:55









Alex HowanskyAlex Howansky

36k55682




36k55682













  • I'm not sure if that's exactly what I was getting at, sorry for any confusion. Some times the details object only has an element with the key of "1", but I would still want to create data in the array with one of "2"

    – Whisou138
    Jan 18 at 18:56











  • @Whisou138 this looks like it would produce the output you showed in the edit you just made to your question

    – Don't Panic
    Jan 18 at 18:58






  • 1





    Right. If your original object only had one item and you created an array with 3 values, then the pad would expand that to 6. If your original object had two items and you created an array with 6 values, then the pad would do nothing.

    – Alex Howansky
    Jan 18 at 18:58













  • Ok so I think that makes sense but I found an issue. When I run it, it doesn't fill because I've already put things in the array before this so there's always 6 items basically. Is there a way to check in the loop so that if there's only one then add another set?

    – Whisou138
    Jan 18 at 19:21











  • So there's already 7 values in the skuItem array by the time it gets to this foreach loop

    – Whisou138
    Jan 18 at 19:22



















  • I'm not sure if that's exactly what I was getting at, sorry for any confusion. Some times the details object only has an element with the key of "1", but I would still want to create data in the array with one of "2"

    – Whisou138
    Jan 18 at 18:56











  • @Whisou138 this looks like it would produce the output you showed in the edit you just made to your question

    – Don't Panic
    Jan 18 at 18:58






  • 1





    Right. If your original object only had one item and you created an array with 3 values, then the pad would expand that to 6. If your original object had two items and you created an array with 6 values, then the pad would do nothing.

    – Alex Howansky
    Jan 18 at 18:58













  • Ok so I think that makes sense but I found an issue. When I run it, it doesn't fill because I've already put things in the array before this so there's always 6 items basically. Is there a way to check in the loop so that if there's only one then add another set?

    – Whisou138
    Jan 18 at 19:21











  • So there's already 7 values in the skuItem array by the time it gets to this foreach loop

    – Whisou138
    Jan 18 at 19:22

















I'm not sure if that's exactly what I was getting at, sorry for any confusion. Some times the details object only has an element with the key of "1", but I would still want to create data in the array with one of "2"

– Whisou138
Jan 18 at 18:56





I'm not sure if that's exactly what I was getting at, sorry for any confusion. Some times the details object only has an element with the key of "1", but I would still want to create data in the array with one of "2"

– Whisou138
Jan 18 at 18:56













@Whisou138 this looks like it would produce the output you showed in the edit you just made to your question

– Don't Panic
Jan 18 at 18:58





@Whisou138 this looks like it would produce the output you showed in the edit you just made to your question

– Don't Panic
Jan 18 at 18:58




1




1





Right. If your original object only had one item and you created an array with 3 values, then the pad would expand that to 6. If your original object had two items and you created an array with 6 values, then the pad would do nothing.

– Alex Howansky
Jan 18 at 18:58







Right. If your original object only had one item and you created an array with 3 values, then the pad would expand that to 6. If your original object had two items and you created an array with 6 values, then the pad would do nothing.

– Alex Howansky
Jan 18 at 18:58















Ok so I think that makes sense but I found an issue. When I run it, it doesn't fill because I've already put things in the array before this so there's always 6 items basically. Is there a way to check in the loop so that if there's only one then add another set?

– Whisou138
Jan 18 at 19:21





Ok so I think that makes sense but I found an issue. When I run it, it doesn't fill because I've already put things in the array before this so there's always 6 items basically. Is there a way to check in the loop so that if there's only one then add another set?

– Whisou138
Jan 18 at 19:21













So there's already 7 values in the skuItem array by the time it gets to this foreach loop

– Whisou138
Jan 18 at 19:22





So there's already 7 values in the skuItem array by the time it gets to this foreach loop

– Whisou138
Jan 18 at 19:22













0














You can create a template of what you want and replace with what you create in the loop:



$skuItem = array_replace(array_fill(0, 6, 0), $skuItem);


array_pad is probably better for this trivial example, but consider if you have a variety of values:



$temp = array('x', 'y', 'z', 'x', 'y', 'z');
$skuItem = array_replace($temp, $skuItem);


Or:



$temp = array('x', 'y', 'z');
if(count($skuItem) != 6) {
$skuItem = array_merge($skuItem, $temp);
}





share|improve this answer


























  • is there a way in that if statement to check if the foreach on details contained one set or two instead?

    – Whisou138
    Jan 18 at 19:21











  • Before the loop just check count($product->info->details). But since you show 3 in each object then if there are 3 in result array then there was 1 if there are 6 then there are 2, etc...

    – AbraCadaver
    Jan 18 at 19:24













  • Can you kind of show how I would use the count to dictate whether or not to add zeroes though?

    – Whisou138
    Jan 18 at 19:30











  • You'll need to be more specific. My first code replaces six 0s with what you generate in the loop. If loop generates three values then they replace the first three 0s, if loop generates six values then all 0s are replaced by what you generated in the loop. You will always have 6 in result.

    – AbraCadaver
    Jan 18 at 19:35


















0














You can create a template of what you want and replace with what you create in the loop:



$skuItem = array_replace(array_fill(0, 6, 0), $skuItem);


array_pad is probably better for this trivial example, but consider if you have a variety of values:



$temp = array('x', 'y', 'z', 'x', 'y', 'z');
$skuItem = array_replace($temp, $skuItem);


Or:



$temp = array('x', 'y', 'z');
if(count($skuItem) != 6) {
$skuItem = array_merge($skuItem, $temp);
}





share|improve this answer


























  • is there a way in that if statement to check if the foreach on details contained one set or two instead?

    – Whisou138
    Jan 18 at 19:21











  • Before the loop just check count($product->info->details). But since you show 3 in each object then if there are 3 in result array then there was 1 if there are 6 then there are 2, etc...

    – AbraCadaver
    Jan 18 at 19:24













  • Can you kind of show how I would use the count to dictate whether or not to add zeroes though?

    – Whisou138
    Jan 18 at 19:30











  • You'll need to be more specific. My first code replaces six 0s with what you generate in the loop. If loop generates three values then they replace the first three 0s, if loop generates six values then all 0s are replaced by what you generated in the loop. You will always have 6 in result.

    – AbraCadaver
    Jan 18 at 19:35
















0












0








0







You can create a template of what you want and replace with what you create in the loop:



$skuItem = array_replace(array_fill(0, 6, 0), $skuItem);


array_pad is probably better for this trivial example, but consider if you have a variety of values:



$temp = array('x', 'y', 'z', 'x', 'y', 'z');
$skuItem = array_replace($temp, $skuItem);


Or:



$temp = array('x', 'y', 'z');
if(count($skuItem) != 6) {
$skuItem = array_merge($skuItem, $temp);
}





share|improve this answer















You can create a template of what you want and replace with what you create in the loop:



$skuItem = array_replace(array_fill(0, 6, 0), $skuItem);


array_pad is probably better for this trivial example, but consider if you have a variety of values:



$temp = array('x', 'y', 'z', 'x', 'y', 'z');
$skuItem = array_replace($temp, $skuItem);


Or:



$temp = array('x', 'y', 'z');
if(count($skuItem) != 6) {
$skuItem = array_merge($skuItem, $temp);
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 18 at 19:18

























answered Jan 18 at 19:12









AbraCadaverAbraCadaver

56.8k73965




56.8k73965













  • is there a way in that if statement to check if the foreach on details contained one set or two instead?

    – Whisou138
    Jan 18 at 19:21











  • Before the loop just check count($product->info->details). But since you show 3 in each object then if there are 3 in result array then there was 1 if there are 6 then there are 2, etc...

    – AbraCadaver
    Jan 18 at 19:24













  • Can you kind of show how I would use the count to dictate whether or not to add zeroes though?

    – Whisou138
    Jan 18 at 19:30











  • You'll need to be more specific. My first code replaces six 0s with what you generate in the loop. If loop generates three values then they replace the first three 0s, if loop generates six values then all 0s are replaced by what you generated in the loop. You will always have 6 in result.

    – AbraCadaver
    Jan 18 at 19:35





















  • is there a way in that if statement to check if the foreach on details contained one set or two instead?

    – Whisou138
    Jan 18 at 19:21











  • Before the loop just check count($product->info->details). But since you show 3 in each object then if there are 3 in result array then there was 1 if there are 6 then there are 2, etc...

    – AbraCadaver
    Jan 18 at 19:24













  • Can you kind of show how I would use the count to dictate whether or not to add zeroes though?

    – Whisou138
    Jan 18 at 19:30











  • You'll need to be more specific. My first code replaces six 0s with what you generate in the loop. If loop generates three values then they replace the first three 0s, if loop generates six values then all 0s are replaced by what you generated in the loop. You will always have 6 in result.

    – AbraCadaver
    Jan 18 at 19:35



















is there a way in that if statement to check if the foreach on details contained one set or two instead?

– Whisou138
Jan 18 at 19:21





is there a way in that if statement to check if the foreach on details contained one set or two instead?

– Whisou138
Jan 18 at 19:21













Before the loop just check count($product->info->details). But since you show 3 in each object then if there are 3 in result array then there was 1 if there are 6 then there are 2, etc...

– AbraCadaver
Jan 18 at 19:24







Before the loop just check count($product->info->details). But since you show 3 in each object then if there are 3 in result array then there was 1 if there are 6 then there are 2, etc...

– AbraCadaver
Jan 18 at 19:24















Can you kind of show how I would use the count to dictate whether or not to add zeroes though?

– Whisou138
Jan 18 at 19:30





Can you kind of show how I would use the count to dictate whether or not to add zeroes though?

– Whisou138
Jan 18 at 19:30













You'll need to be more specific. My first code replaces six 0s with what you generate in the loop. If loop generates three values then they replace the first three 0s, if loop generates six values then all 0s are replaced by what you generated in the loop. You will always have 6 in result.

– AbraCadaver
Jan 18 at 19:35







You'll need to be more specific. My first code replaces six 0s with what you generate in the loop. If loop generates three values then they replace the first three 0s, if loop generates six values then all 0s are replaced by what you generated in the loop. You will always have 6 in result.

– AbraCadaver
Jan 18 at 19:35




















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%2f54259880%2fpadding-data-for-sometimes-missing-object-index%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

Callistus III

Plistias Cous

Index Sanctorum