assigned variable is not working in do while loop in using PHP
I am working on Do While loop
in my project its working fine first time.
Before while statement
, I assigned a value to an array I could able to print the array successfully at bottom of the code, BUT its become 0 when I check at top of the loop.
Code:
$looparray = array();
$loopend = 0;
$arraymer = array();
$poolafirtsid = $previous_array_values; //previous array values
do {
if (sizeof($looparray) == 0) {
$firstsponarray = $poolafirtsid;
} else {
$firstsponarray = $looparray;
}
$firstsponarray = getUserArray($poolafirtsid);
//get user arraylist of first
foreach ($firstsponarray as $avalue) {
$rooparray = membercount($avalue);
$bsponarray = getUserArray($avalue);
//get second users arraylist 9
if (sizeof($bsponarray > 0)) {
$barraymer = array_merge($barraymer, $bsponarray);
}
$aarraylist[$avalue] = $rooparray;
}
$asmallestsponid = getSmallestID($aarraylist);
//get smallest id in the array
if (membercount($asmallestsponid) < 3) {
$loopend = 1;
} else {
global $pooldata;
if (count($barraymer) > 0) {
$pooldata = $barraymer;
}
print_r($pooldata);
}
} while ($loopend == 1);
When I print in else its working but I am unable to print starting of do loop its showing array size is 0
php loops while-loop do-while
|
show 4 more comments
I am working on Do While loop
in my project its working fine first time.
Before while statement
, I assigned a value to an array I could able to print the array successfully at bottom of the code, BUT its become 0 when I check at top of the loop.
Code:
$looparray = array();
$loopend = 0;
$arraymer = array();
$poolafirtsid = $previous_array_values; //previous array values
do {
if (sizeof($looparray) == 0) {
$firstsponarray = $poolafirtsid;
} else {
$firstsponarray = $looparray;
}
$firstsponarray = getUserArray($poolafirtsid);
//get user arraylist of first
foreach ($firstsponarray as $avalue) {
$rooparray = membercount($avalue);
$bsponarray = getUserArray($avalue);
//get second users arraylist 9
if (sizeof($bsponarray > 0)) {
$barraymer = array_merge($barraymer, $bsponarray);
}
$aarraylist[$avalue] = $rooparray;
}
$asmallestsponid = getSmallestID($aarraylist);
//get smallest id in the array
if (membercount($asmallestsponid) < 3) {
$loopend = 1;
} else {
global $pooldata;
if (count($barraymer) > 0) {
$pooldata = $barraymer;
}
print_r($pooldata);
}
} while ($loopend == 1);
When I print in else its working but I am unable to print starting of do loop its showing array size is 0
php loops while-loop do-while
it's impossible to debug without seeing the code or returned values ofmembercount()
,getUserArray()
,getSmallestID()
functions. Consider updating your question with their returned values instead of calls, so provide MVCE with hardcoded values and check if there is still error with them
– Alexey
Nov 18 '18 at 21:13
But my code is working fine I am getting values. My concern is $looparray array size is becoming 0 when I check on top of code. But I am getting correct results at bottom of code in else condition.
– Asesha George
Nov 18 '18 at 21:41
as said, if you're looking for help we need the values that these functions return, i.e. MCVE
– Alexey
Nov 18 '18 at 21:47
please see the result which I am getting at the bottom of the code when I use print_r, I am unable to access at top of the code to reuse
– Asesha George
Nov 19 '18 at 3:22
2
Also consider followingPSR-x
in the future and please realise thatvariable naming
can escalate your code understanding A LOT. Never underestimate the power of semantics in the code.
– Diogo Santo
Nov 23 '18 at 12:02
|
show 4 more comments
I am working on Do While loop
in my project its working fine first time.
Before while statement
, I assigned a value to an array I could able to print the array successfully at bottom of the code, BUT its become 0 when I check at top of the loop.
Code:
$looparray = array();
$loopend = 0;
$arraymer = array();
$poolafirtsid = $previous_array_values; //previous array values
do {
if (sizeof($looparray) == 0) {
$firstsponarray = $poolafirtsid;
} else {
$firstsponarray = $looparray;
}
$firstsponarray = getUserArray($poolafirtsid);
//get user arraylist of first
foreach ($firstsponarray as $avalue) {
$rooparray = membercount($avalue);
$bsponarray = getUserArray($avalue);
//get second users arraylist 9
if (sizeof($bsponarray > 0)) {
$barraymer = array_merge($barraymer, $bsponarray);
}
$aarraylist[$avalue] = $rooparray;
}
$asmallestsponid = getSmallestID($aarraylist);
//get smallest id in the array
if (membercount($asmallestsponid) < 3) {
$loopend = 1;
} else {
global $pooldata;
if (count($barraymer) > 0) {
$pooldata = $barraymer;
}
print_r($pooldata);
}
} while ($loopend == 1);
When I print in else its working but I am unable to print starting of do loop its showing array size is 0
php loops while-loop do-while
I am working on Do While loop
in my project its working fine first time.
Before while statement
, I assigned a value to an array I could able to print the array successfully at bottom of the code, BUT its become 0 when I check at top of the loop.
Code:
$looparray = array();
$loopend = 0;
$arraymer = array();
$poolafirtsid = $previous_array_values; //previous array values
do {
if (sizeof($looparray) == 0) {
$firstsponarray = $poolafirtsid;
} else {
$firstsponarray = $looparray;
}
$firstsponarray = getUserArray($poolafirtsid);
//get user arraylist of first
foreach ($firstsponarray as $avalue) {
$rooparray = membercount($avalue);
$bsponarray = getUserArray($avalue);
//get second users arraylist 9
if (sizeof($bsponarray > 0)) {
$barraymer = array_merge($barraymer, $bsponarray);
}
$aarraylist[$avalue] = $rooparray;
}
$asmallestsponid = getSmallestID($aarraylist);
//get smallest id in the array
if (membercount($asmallestsponid) < 3) {
$loopend = 1;
} else {
global $pooldata;
if (count($barraymer) > 0) {
$pooldata = $barraymer;
}
print_r($pooldata);
}
} while ($loopend == 1);
When I print in else its working but I am unable to print starting of do loop its showing array size is 0
php loops while-loop do-while
php loops while-loop do-while
edited Nov 29 '18 at 16:25
David Winder
3,6483727
3,6483727
asked Nov 18 '18 at 20:18
Asesha GeorgeAsesha George
68811034
68811034
it's impossible to debug without seeing the code or returned values ofmembercount()
,getUserArray()
,getSmallestID()
functions. Consider updating your question with their returned values instead of calls, so provide MVCE with hardcoded values and check if there is still error with them
– Alexey
Nov 18 '18 at 21:13
But my code is working fine I am getting values. My concern is $looparray array size is becoming 0 when I check on top of code. But I am getting correct results at bottom of code in else condition.
– Asesha George
Nov 18 '18 at 21:41
as said, if you're looking for help we need the values that these functions return, i.e. MCVE
– Alexey
Nov 18 '18 at 21:47
please see the result which I am getting at the bottom of the code when I use print_r, I am unable to access at top of the code to reuse
– Asesha George
Nov 19 '18 at 3:22
2
Also consider followingPSR-x
in the future and please realise thatvariable naming
can escalate your code understanding A LOT. Never underestimate the power of semantics in the code.
– Diogo Santo
Nov 23 '18 at 12:02
|
show 4 more comments
it's impossible to debug without seeing the code or returned values ofmembercount()
,getUserArray()
,getSmallestID()
functions. Consider updating your question with their returned values instead of calls, so provide MVCE with hardcoded values and check if there is still error with them
– Alexey
Nov 18 '18 at 21:13
But my code is working fine I am getting values. My concern is $looparray array size is becoming 0 when I check on top of code. But I am getting correct results at bottom of code in else condition.
– Asesha George
Nov 18 '18 at 21:41
as said, if you're looking for help we need the values that these functions return, i.e. MCVE
– Alexey
Nov 18 '18 at 21:47
please see the result which I am getting at the bottom of the code when I use print_r, I am unable to access at top of the code to reuse
– Asesha George
Nov 19 '18 at 3:22
2
Also consider followingPSR-x
in the future and please realise thatvariable naming
can escalate your code understanding A LOT. Never underestimate the power of semantics in the code.
– Diogo Santo
Nov 23 '18 at 12:02
it's impossible to debug without seeing the code or returned values of
membercount()
, getUserArray()
, getSmallestID()
functions. Consider updating your question with their returned values instead of calls, so provide MVCE with hardcoded values and check if there is still error with them– Alexey
Nov 18 '18 at 21:13
it's impossible to debug without seeing the code or returned values of
membercount()
, getUserArray()
, getSmallestID()
functions. Consider updating your question with their returned values instead of calls, so provide MVCE with hardcoded values and check if there is still error with them– Alexey
Nov 18 '18 at 21:13
But my code is working fine I am getting values. My concern is $looparray array size is becoming 0 when I check on top of code. But I am getting correct results at bottom of code in else condition.
– Asesha George
Nov 18 '18 at 21:41
But my code is working fine I am getting values. My concern is $looparray array size is becoming 0 when I check on top of code. But I am getting correct results at bottom of code in else condition.
– Asesha George
Nov 18 '18 at 21:41
as said, if you're looking for help we need the values that these functions return, i.e. MCVE
– Alexey
Nov 18 '18 at 21:47
as said, if you're looking for help we need the values that these functions return, i.e. MCVE
– Alexey
Nov 18 '18 at 21:47
please see the result which I am getting at the bottom of the code when I use print_r, I am unable to access at top of the code to reuse
– Asesha George
Nov 19 '18 at 3:22
please see the result which I am getting at the bottom of the code when I use print_r, I am unable to access at top of the code to reuse
– Asesha George
Nov 19 '18 at 3:22
2
2
Also consider following
PSR-x
in the future and please realise that variable naming
can escalate your code understanding A LOT. Never underestimate the power of semantics in the code.– Diogo Santo
Nov 23 '18 at 12:02
Also consider following
PSR-x
in the future and please realise that variable naming
can escalate your code understanding A LOT. Never underestimate the power of semantics in the code.– Diogo Santo
Nov 23 '18 at 12:02
|
show 4 more comments
3 Answers
3
active
oldest
votes
I will ignore all the name issues but address your while
loop issue:
$loopend =0;
do {
...
if(membercount($asmallestsponid)<3) {
$loopend = 1;
}else{
...
}
while ($loopend == 1);
There are 2 options:
The if condition is true: if so,
$loopend
will get 1 so the loop continue (which not seem fit the call him "loop end" but what ever...)The if condition is false: then the
$loopend
stay the same (init as 0) so the loop will stops
IMHO - this will simplify your loop:
do {
...
while (membercount($asmallestsponid)<3);
ya this is what i am looking for. Thank you very much. and what is IMHO?
– Asesha George
Nov 29 '18 at 15:30
"In my humble opinion". Glad to help!
– David Winder
Nov 29 '18 at 16:07
add a comment |
We don't know what membercount($asmallestsponid)
returns, but it appears (most likely) that on the 1st pass it gets into
} else {
$looparray = $arraymer;
//print_r($looparray);
}
the value of $loopend
doesn't change, i.e. remains at 0
and on the first pass it compares 0
to 1
and decides to exit the do {} while
loop as 0 != 1
but my condition is it should only exit if $loopend is equaled to 1 else it should go to top and execute $looparray.
– Asesha George
Nov 19 '18 at 8:28
membercount is fine it's returning the value and satisfying the condition when it comes to else I assigned an array to $looparry while I print it's showing the result I want to use this array at the top so it will do the next step if I use "for" loop I could able to get the $lopparray but in do_while the size of array is zero
– Asesha George
Nov 19 '18 at 8:34
I don't understand. If it goes intoif(membercount($asmallestsponid)<3)
there is a break statement causing to go out of the do/while loop completely if it gets there once. If it gets to else , there is no change to$loopend
so your do/while can only work once
– Alexey
Nov 19 '18 at 9:40
yes, you are correct if it goes into if(membercount($asmallestsponid)<3) it will exit the loop. but if the condition is not satisfied it will go to else so there is no break statement in else. if member count is less then 3, it will insert a row in my database if it's greater then 3 its will go to else and fetch all the id numbers into an array and go to the top and execute the array. i am getting the array in my $looparray my only concern is how to send this array top of the loop. i hope you understand
– Asesha George
Nov 19 '18 at 10:02
I'm telling you that if it goes into else, it won't change the value of$loopend
to 1 and this will end the loop as well
– Alexey
Nov 19 '18 at 19:23
add a comment |
There are several problems with your code. First of all, this does nothing:
if (sizeof($looparray)==0) {
$firstsponarray= $poolafirtsid;
} else {
$firstsponarray= $looparray;
}
since the very next line after that piece of code is:
$firstsponarray= getUserArray($poolafirtsid);
which overrides any prior assignment of $firstsponarray
.
Second, the value of $looparray
doesn't change at all in the do
loop, so it'll always be an empty array. I found this line:
$rooparray=membercount($avalue);
which I assume is a typo and the correct line is $looparray=membercount($avalue);
. Same with the line $aarraylist[$avalue]=$rooparray;
. However, changing that also does nothing since $firstponarray
will never be equal to $looparray
for the reason I described at the top.
Try debugging your code first, and if the problem persists post the updated code.
add a comment |
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%2f53365046%2fassigned-variable-is-not-working-in-do-while-loop-in-using-php%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I will ignore all the name issues but address your while
loop issue:
$loopend =0;
do {
...
if(membercount($asmallestsponid)<3) {
$loopend = 1;
}else{
...
}
while ($loopend == 1);
There are 2 options:
The if condition is true: if so,
$loopend
will get 1 so the loop continue (which not seem fit the call him "loop end" but what ever...)The if condition is false: then the
$loopend
stay the same (init as 0) so the loop will stops
IMHO - this will simplify your loop:
do {
...
while (membercount($asmallestsponid)<3);
ya this is what i am looking for. Thank you very much. and what is IMHO?
– Asesha George
Nov 29 '18 at 15:30
"In my humble opinion". Glad to help!
– David Winder
Nov 29 '18 at 16:07
add a comment |
I will ignore all the name issues but address your while
loop issue:
$loopend =0;
do {
...
if(membercount($asmallestsponid)<3) {
$loopend = 1;
}else{
...
}
while ($loopend == 1);
There are 2 options:
The if condition is true: if so,
$loopend
will get 1 so the loop continue (which not seem fit the call him "loop end" but what ever...)The if condition is false: then the
$loopend
stay the same (init as 0) so the loop will stops
IMHO - this will simplify your loop:
do {
...
while (membercount($asmallestsponid)<3);
ya this is what i am looking for. Thank you very much. and what is IMHO?
– Asesha George
Nov 29 '18 at 15:30
"In my humble opinion". Glad to help!
– David Winder
Nov 29 '18 at 16:07
add a comment |
I will ignore all the name issues but address your while
loop issue:
$loopend =0;
do {
...
if(membercount($asmallestsponid)<3) {
$loopend = 1;
}else{
...
}
while ($loopend == 1);
There are 2 options:
The if condition is true: if so,
$loopend
will get 1 so the loop continue (which not seem fit the call him "loop end" but what ever...)The if condition is false: then the
$loopend
stay the same (init as 0) so the loop will stops
IMHO - this will simplify your loop:
do {
...
while (membercount($asmallestsponid)<3);
I will ignore all the name issues but address your while
loop issue:
$loopend =0;
do {
...
if(membercount($asmallestsponid)<3) {
$loopend = 1;
}else{
...
}
while ($loopend == 1);
There are 2 options:
The if condition is true: if so,
$loopend
will get 1 so the loop continue (which not seem fit the call him "loop end" but what ever...)The if condition is false: then the
$loopend
stay the same (init as 0) so the loop will stops
IMHO - this will simplify your loop:
do {
...
while (membercount($asmallestsponid)<3);
edited Dec 1 '18 at 17:24
answered Nov 29 '18 at 14:10
David WinderDavid Winder
3,6483727
3,6483727
ya this is what i am looking for. Thank you very much. and what is IMHO?
– Asesha George
Nov 29 '18 at 15:30
"In my humble opinion". Glad to help!
– David Winder
Nov 29 '18 at 16:07
add a comment |
ya this is what i am looking for. Thank you very much. and what is IMHO?
– Asesha George
Nov 29 '18 at 15:30
"In my humble opinion". Glad to help!
– David Winder
Nov 29 '18 at 16:07
ya this is what i am looking for. Thank you very much. and what is IMHO?
– Asesha George
Nov 29 '18 at 15:30
ya this is what i am looking for. Thank you very much. and what is IMHO?
– Asesha George
Nov 29 '18 at 15:30
"In my humble opinion". Glad to help!
– David Winder
Nov 29 '18 at 16:07
"In my humble opinion". Glad to help!
– David Winder
Nov 29 '18 at 16:07
add a comment |
We don't know what membercount($asmallestsponid)
returns, but it appears (most likely) that on the 1st pass it gets into
} else {
$looparray = $arraymer;
//print_r($looparray);
}
the value of $loopend
doesn't change, i.e. remains at 0
and on the first pass it compares 0
to 1
and decides to exit the do {} while
loop as 0 != 1
but my condition is it should only exit if $loopend is equaled to 1 else it should go to top and execute $looparray.
– Asesha George
Nov 19 '18 at 8:28
membercount is fine it's returning the value and satisfying the condition when it comes to else I assigned an array to $looparry while I print it's showing the result I want to use this array at the top so it will do the next step if I use "for" loop I could able to get the $lopparray but in do_while the size of array is zero
– Asesha George
Nov 19 '18 at 8:34
I don't understand. If it goes intoif(membercount($asmallestsponid)<3)
there is a break statement causing to go out of the do/while loop completely if it gets there once. If it gets to else , there is no change to$loopend
so your do/while can only work once
– Alexey
Nov 19 '18 at 9:40
yes, you are correct if it goes into if(membercount($asmallestsponid)<3) it will exit the loop. but if the condition is not satisfied it will go to else so there is no break statement in else. if member count is less then 3, it will insert a row in my database if it's greater then 3 its will go to else and fetch all the id numbers into an array and go to the top and execute the array. i am getting the array in my $looparray my only concern is how to send this array top of the loop. i hope you understand
– Asesha George
Nov 19 '18 at 10:02
I'm telling you that if it goes into else, it won't change the value of$loopend
to 1 and this will end the loop as well
– Alexey
Nov 19 '18 at 19:23
add a comment |
We don't know what membercount($asmallestsponid)
returns, but it appears (most likely) that on the 1st pass it gets into
} else {
$looparray = $arraymer;
//print_r($looparray);
}
the value of $loopend
doesn't change, i.e. remains at 0
and on the first pass it compares 0
to 1
and decides to exit the do {} while
loop as 0 != 1
but my condition is it should only exit if $loopend is equaled to 1 else it should go to top and execute $looparray.
– Asesha George
Nov 19 '18 at 8:28
membercount is fine it's returning the value and satisfying the condition when it comes to else I assigned an array to $looparry while I print it's showing the result I want to use this array at the top so it will do the next step if I use "for" loop I could able to get the $lopparray but in do_while the size of array is zero
– Asesha George
Nov 19 '18 at 8:34
I don't understand. If it goes intoif(membercount($asmallestsponid)<3)
there is a break statement causing to go out of the do/while loop completely if it gets there once. If it gets to else , there is no change to$loopend
so your do/while can only work once
– Alexey
Nov 19 '18 at 9:40
yes, you are correct if it goes into if(membercount($asmallestsponid)<3) it will exit the loop. but if the condition is not satisfied it will go to else so there is no break statement in else. if member count is less then 3, it will insert a row in my database if it's greater then 3 its will go to else and fetch all the id numbers into an array and go to the top and execute the array. i am getting the array in my $looparray my only concern is how to send this array top of the loop. i hope you understand
– Asesha George
Nov 19 '18 at 10:02
I'm telling you that if it goes into else, it won't change the value of$loopend
to 1 and this will end the loop as well
– Alexey
Nov 19 '18 at 19:23
add a comment |
We don't know what membercount($asmallestsponid)
returns, but it appears (most likely) that on the 1st pass it gets into
} else {
$looparray = $arraymer;
//print_r($looparray);
}
the value of $loopend
doesn't change, i.e. remains at 0
and on the first pass it compares 0
to 1
and decides to exit the do {} while
loop as 0 != 1
We don't know what membercount($asmallestsponid)
returns, but it appears (most likely) that on the 1st pass it gets into
} else {
$looparray = $arraymer;
//print_r($looparray);
}
the value of $loopend
doesn't change, i.e. remains at 0
and on the first pass it compares 0
to 1
and decides to exit the do {} while
loop as 0 != 1
answered Nov 19 '18 at 8:08
AlexeyAlexey
1,94242036
1,94242036
but my condition is it should only exit if $loopend is equaled to 1 else it should go to top and execute $looparray.
– Asesha George
Nov 19 '18 at 8:28
membercount is fine it's returning the value and satisfying the condition when it comes to else I assigned an array to $looparry while I print it's showing the result I want to use this array at the top so it will do the next step if I use "for" loop I could able to get the $lopparray but in do_while the size of array is zero
– Asesha George
Nov 19 '18 at 8:34
I don't understand. If it goes intoif(membercount($asmallestsponid)<3)
there is a break statement causing to go out of the do/while loop completely if it gets there once. If it gets to else , there is no change to$loopend
so your do/while can only work once
– Alexey
Nov 19 '18 at 9:40
yes, you are correct if it goes into if(membercount($asmallestsponid)<3) it will exit the loop. but if the condition is not satisfied it will go to else so there is no break statement in else. if member count is less then 3, it will insert a row in my database if it's greater then 3 its will go to else and fetch all the id numbers into an array and go to the top and execute the array. i am getting the array in my $looparray my only concern is how to send this array top of the loop. i hope you understand
– Asesha George
Nov 19 '18 at 10:02
I'm telling you that if it goes into else, it won't change the value of$loopend
to 1 and this will end the loop as well
– Alexey
Nov 19 '18 at 19:23
add a comment |
but my condition is it should only exit if $loopend is equaled to 1 else it should go to top and execute $looparray.
– Asesha George
Nov 19 '18 at 8:28
membercount is fine it's returning the value and satisfying the condition when it comes to else I assigned an array to $looparry while I print it's showing the result I want to use this array at the top so it will do the next step if I use "for" loop I could able to get the $lopparray but in do_while the size of array is zero
– Asesha George
Nov 19 '18 at 8:34
I don't understand. If it goes intoif(membercount($asmallestsponid)<3)
there is a break statement causing to go out of the do/while loop completely if it gets there once. If it gets to else , there is no change to$loopend
so your do/while can only work once
– Alexey
Nov 19 '18 at 9:40
yes, you are correct if it goes into if(membercount($asmallestsponid)<3) it will exit the loop. but if the condition is not satisfied it will go to else so there is no break statement in else. if member count is less then 3, it will insert a row in my database if it's greater then 3 its will go to else and fetch all the id numbers into an array and go to the top and execute the array. i am getting the array in my $looparray my only concern is how to send this array top of the loop. i hope you understand
– Asesha George
Nov 19 '18 at 10:02
I'm telling you that if it goes into else, it won't change the value of$loopend
to 1 and this will end the loop as well
– Alexey
Nov 19 '18 at 19:23
but my condition is it should only exit if $loopend is equaled to 1 else it should go to top and execute $looparray.
– Asesha George
Nov 19 '18 at 8:28
but my condition is it should only exit if $loopend is equaled to 1 else it should go to top and execute $looparray.
– Asesha George
Nov 19 '18 at 8:28
membercount is fine it's returning the value and satisfying the condition when it comes to else I assigned an array to $looparry while I print it's showing the result I want to use this array at the top so it will do the next step if I use "for" loop I could able to get the $lopparray but in do_while the size of array is zero
– Asesha George
Nov 19 '18 at 8:34
membercount is fine it's returning the value and satisfying the condition when it comes to else I assigned an array to $looparry while I print it's showing the result I want to use this array at the top so it will do the next step if I use "for" loop I could able to get the $lopparray but in do_while the size of array is zero
– Asesha George
Nov 19 '18 at 8:34
I don't understand. If it goes into
if(membercount($asmallestsponid)<3)
there is a break statement causing to go out of the do/while loop completely if it gets there once. If it gets to else , there is no change to $loopend
so your do/while can only work once– Alexey
Nov 19 '18 at 9:40
I don't understand. If it goes into
if(membercount($asmallestsponid)<3)
there is a break statement causing to go out of the do/while loop completely if it gets there once. If it gets to else , there is no change to $loopend
so your do/while can only work once– Alexey
Nov 19 '18 at 9:40
yes, you are correct if it goes into if(membercount($asmallestsponid)<3) it will exit the loop. but if the condition is not satisfied it will go to else so there is no break statement in else. if member count is less then 3, it will insert a row in my database if it's greater then 3 its will go to else and fetch all the id numbers into an array and go to the top and execute the array. i am getting the array in my $looparray my only concern is how to send this array top of the loop. i hope you understand
– Asesha George
Nov 19 '18 at 10:02
yes, you are correct if it goes into if(membercount($asmallestsponid)<3) it will exit the loop. but if the condition is not satisfied it will go to else so there is no break statement in else. if member count is less then 3, it will insert a row in my database if it's greater then 3 its will go to else and fetch all the id numbers into an array and go to the top and execute the array. i am getting the array in my $looparray my only concern is how to send this array top of the loop. i hope you understand
– Asesha George
Nov 19 '18 at 10:02
I'm telling you that if it goes into else, it won't change the value of
$loopend
to 1 and this will end the loop as well– Alexey
Nov 19 '18 at 19:23
I'm telling you that if it goes into else, it won't change the value of
$loopend
to 1 and this will end the loop as well– Alexey
Nov 19 '18 at 19:23
add a comment |
There are several problems with your code. First of all, this does nothing:
if (sizeof($looparray)==0) {
$firstsponarray= $poolafirtsid;
} else {
$firstsponarray= $looparray;
}
since the very next line after that piece of code is:
$firstsponarray= getUserArray($poolafirtsid);
which overrides any prior assignment of $firstsponarray
.
Second, the value of $looparray
doesn't change at all in the do
loop, so it'll always be an empty array. I found this line:
$rooparray=membercount($avalue);
which I assume is a typo and the correct line is $looparray=membercount($avalue);
. Same with the line $aarraylist[$avalue]=$rooparray;
. However, changing that also does nothing since $firstponarray
will never be equal to $looparray
for the reason I described at the top.
Try debugging your code first, and if the problem persists post the updated code.
add a comment |
There are several problems with your code. First of all, this does nothing:
if (sizeof($looparray)==0) {
$firstsponarray= $poolafirtsid;
} else {
$firstsponarray= $looparray;
}
since the very next line after that piece of code is:
$firstsponarray= getUserArray($poolafirtsid);
which overrides any prior assignment of $firstsponarray
.
Second, the value of $looparray
doesn't change at all in the do
loop, so it'll always be an empty array. I found this line:
$rooparray=membercount($avalue);
which I assume is a typo and the correct line is $looparray=membercount($avalue);
. Same with the line $aarraylist[$avalue]=$rooparray;
. However, changing that also does nothing since $firstponarray
will never be equal to $looparray
for the reason I described at the top.
Try debugging your code first, and if the problem persists post the updated code.
add a comment |
There are several problems with your code. First of all, this does nothing:
if (sizeof($looparray)==0) {
$firstsponarray= $poolafirtsid;
} else {
$firstsponarray= $looparray;
}
since the very next line after that piece of code is:
$firstsponarray= getUserArray($poolafirtsid);
which overrides any prior assignment of $firstsponarray
.
Second, the value of $looparray
doesn't change at all in the do
loop, so it'll always be an empty array. I found this line:
$rooparray=membercount($avalue);
which I assume is a typo and the correct line is $looparray=membercount($avalue);
. Same with the line $aarraylist[$avalue]=$rooparray;
. However, changing that also does nothing since $firstponarray
will never be equal to $looparray
for the reason I described at the top.
Try debugging your code first, and if the problem persists post the updated code.
There are several problems with your code. First of all, this does nothing:
if (sizeof($looparray)==0) {
$firstsponarray= $poolafirtsid;
} else {
$firstsponarray= $looparray;
}
since the very next line after that piece of code is:
$firstsponarray= getUserArray($poolafirtsid);
which overrides any prior assignment of $firstsponarray
.
Second, the value of $looparray
doesn't change at all in the do
loop, so it'll always be an empty array. I found this line:
$rooparray=membercount($avalue);
which I assume is a typo and the correct line is $looparray=membercount($avalue);
. Same with the line $aarraylist[$avalue]=$rooparray;
. However, changing that also does nothing since $firstponarray
will never be equal to $looparray
for the reason I described at the top.
Try debugging your code first, and if the problem persists post the updated code.
answered Nov 27 '18 at 17:42
José A. ZapataJosé A. Zapata
737212
737212
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53365046%2fassigned-variable-is-not-working-in-do-while-loop-in-using-php%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
it's impossible to debug without seeing the code or returned values of
membercount()
,getUserArray()
,getSmallestID()
functions. Consider updating your question with their returned values instead of calls, so provide MVCE with hardcoded values and check if there is still error with them– Alexey
Nov 18 '18 at 21:13
But my code is working fine I am getting values. My concern is $looparray array size is becoming 0 when I check on top of code. But I am getting correct results at bottom of code in else condition.
– Asesha George
Nov 18 '18 at 21:41
as said, if you're looking for help we need the values that these functions return, i.e. MCVE
– Alexey
Nov 18 '18 at 21:47
please see the result which I am getting at the bottom of the code when I use print_r, I am unable to access at top of the code to reuse
– Asesha George
Nov 19 '18 at 3:22
2
Also consider following
PSR-x
in the future and please realise thatvariable naming
can escalate your code understanding A LOT. Never underestimate the power of semantics in the code.– Diogo Santo
Nov 23 '18 at 12:02