Group by age array returns empty
I'm trying to calculate users age, and then group those results like the following:
public function setAge($users)
{
if($users)
foreach($users as $user)
{
$now = Carbon::now();
$u->age = Carbon::createFromFormat('Y-m-d', $u->birth_date);
$u->age = $now->diffInYears($u->age)
}
return $users;
}
public function groupByAge($users)
{
$ageGroups = ['less than 20', 'more than 20'];
foreach ($users as $u)
switch($u->age) {
case ($u->age < 20)
$ageGroups['less than 20'] += 1;
break;
case($u->age > 20)
$ageGroups['more than 20'] += 1;
break;
}
return $age;
}
public function index()
{
$users = DB::table('users')->get;
$users = $this->setAge($users);
$users = $this->groupByAge($users);
dd($groupByAge);
return view('/users/',['users'=> $users]);
}
However when I dd($groupByAge)
I'm always receiving
empty array like ('key' => 0)
I'm not sure if I'm not passing $users
correctly or what is the issued.
php laravel
add a comment |
I'm trying to calculate users age, and then group those results like the following:
public function setAge($users)
{
if($users)
foreach($users as $user)
{
$now = Carbon::now();
$u->age = Carbon::createFromFormat('Y-m-d', $u->birth_date);
$u->age = $now->diffInYears($u->age)
}
return $users;
}
public function groupByAge($users)
{
$ageGroups = ['less than 20', 'more than 20'];
foreach ($users as $u)
switch($u->age) {
case ($u->age < 20)
$ageGroups['less than 20'] += 1;
break;
case($u->age > 20)
$ageGroups['more than 20'] += 1;
break;
}
return $age;
}
public function index()
{
$users = DB::table('users')->get;
$users = $this->setAge($users);
$users = $this->groupByAge($users);
dd($groupByAge);
return view('/users/',['users'=> $users]);
}
However when I dd($groupByAge)
I'm always receiving
empty array like ('key' => 0)
I'm not sure if I'm not passing $users
correctly or what is the issued.
php laravel
2
$groupByAge
is not the variable you want to dd. instead dd$users
variable
– Rahul Meshram
Jan 2 at 10:38
What if$u->age == 20
?
– kerbholz
Jan 2 at 10:46
1
What doesendforeach
andendif
mean in PHP context? What is$u
? You using itu->birth_date
(btw. missing a $ sign) without declaring it before. Please provide a code example without syntax errors.
– common sense
Jan 2 at 10:49
Check yourgroupByAge
function, it returns$age
which is never set. And thatforeach
isn't closed anywhere? Also,$ageGroup['less then 20']
is not the same as$ageGroup['less than 20']
.
– kerbholz
Jan 2 at 10:54
@commonsenseendif
andendforeach
are alternative syntaxes. Didn't know it either.. BUT:
are missing for the syntax
– Fanie Void
Jan 2 at 11:21
add a comment |
I'm trying to calculate users age, and then group those results like the following:
public function setAge($users)
{
if($users)
foreach($users as $user)
{
$now = Carbon::now();
$u->age = Carbon::createFromFormat('Y-m-d', $u->birth_date);
$u->age = $now->diffInYears($u->age)
}
return $users;
}
public function groupByAge($users)
{
$ageGroups = ['less than 20', 'more than 20'];
foreach ($users as $u)
switch($u->age) {
case ($u->age < 20)
$ageGroups['less than 20'] += 1;
break;
case($u->age > 20)
$ageGroups['more than 20'] += 1;
break;
}
return $age;
}
public function index()
{
$users = DB::table('users')->get;
$users = $this->setAge($users);
$users = $this->groupByAge($users);
dd($groupByAge);
return view('/users/',['users'=> $users]);
}
However when I dd($groupByAge)
I'm always receiving
empty array like ('key' => 0)
I'm not sure if I'm not passing $users
correctly or what is the issued.
php laravel
I'm trying to calculate users age, and then group those results like the following:
public function setAge($users)
{
if($users)
foreach($users as $user)
{
$now = Carbon::now();
$u->age = Carbon::createFromFormat('Y-m-d', $u->birth_date);
$u->age = $now->diffInYears($u->age)
}
return $users;
}
public function groupByAge($users)
{
$ageGroups = ['less than 20', 'more than 20'];
foreach ($users as $u)
switch($u->age) {
case ($u->age < 20)
$ageGroups['less than 20'] += 1;
break;
case($u->age > 20)
$ageGroups['more than 20'] += 1;
break;
}
return $age;
}
public function index()
{
$users = DB::table('users')->get;
$users = $this->setAge($users);
$users = $this->groupByAge($users);
dd($groupByAge);
return view('/users/',['users'=> $users]);
}
However when I dd($groupByAge)
I'm always receiving
empty array like ('key' => 0)
I'm not sure if I'm not passing $users
correctly or what is the issued.
php laravel
php laravel
edited Jan 2 at 18:39
Nick
asked Jan 2 at 10:33
NickNick
208
208
2
$groupByAge
is not the variable you want to dd. instead dd$users
variable
– Rahul Meshram
Jan 2 at 10:38
What if$u->age == 20
?
– kerbholz
Jan 2 at 10:46
1
What doesendforeach
andendif
mean in PHP context? What is$u
? You using itu->birth_date
(btw. missing a $ sign) without declaring it before. Please provide a code example without syntax errors.
– common sense
Jan 2 at 10:49
Check yourgroupByAge
function, it returns$age
which is never set. And thatforeach
isn't closed anywhere? Also,$ageGroup['less then 20']
is not the same as$ageGroup['less than 20']
.
– kerbholz
Jan 2 at 10:54
@commonsenseendif
andendforeach
are alternative syntaxes. Didn't know it either.. BUT:
are missing for the syntax
– Fanie Void
Jan 2 at 11:21
add a comment |
2
$groupByAge
is not the variable you want to dd. instead dd$users
variable
– Rahul Meshram
Jan 2 at 10:38
What if$u->age == 20
?
– kerbholz
Jan 2 at 10:46
1
What doesendforeach
andendif
mean in PHP context? What is$u
? You using itu->birth_date
(btw. missing a $ sign) without declaring it before. Please provide a code example without syntax errors.
– common sense
Jan 2 at 10:49
Check yourgroupByAge
function, it returns$age
which is never set. And thatforeach
isn't closed anywhere? Also,$ageGroup['less then 20']
is not the same as$ageGroup['less than 20']
.
– kerbholz
Jan 2 at 10:54
@commonsenseendif
andendforeach
are alternative syntaxes. Didn't know it either.. BUT:
are missing for the syntax
– Fanie Void
Jan 2 at 11:21
2
2
$groupByAge
is not the variable you want to dd. instead dd $users
variable– Rahul Meshram
Jan 2 at 10:38
$groupByAge
is not the variable you want to dd. instead dd $users
variable– Rahul Meshram
Jan 2 at 10:38
What if
$u->age == 20
?– kerbholz
Jan 2 at 10:46
What if
$u->age == 20
?– kerbholz
Jan 2 at 10:46
1
1
What does
endforeach
and endif
mean in PHP context? What is $u
? You using it u->birth_date
(btw. missing a $ sign) without declaring it before. Please provide a code example without syntax errors.– common sense
Jan 2 at 10:49
What does
endforeach
and endif
mean in PHP context? What is $u
? You using it u->birth_date
(btw. missing a $ sign) without declaring it before. Please provide a code example without syntax errors.– common sense
Jan 2 at 10:49
Check your
groupByAge
function, it returns $age
which is never set. And that foreach
isn't closed anywhere? Also, $ageGroup['less then 20']
is not the same as $ageGroup['less than 20']
.– kerbholz
Jan 2 at 10:54
Check your
groupByAge
function, it returns $age
which is never set. And that foreach
isn't closed anywhere? Also, $ageGroup['less then 20']
is not the same as $ageGroup['less than 20']
.– kerbholz
Jan 2 at 10:54
@commonsense
endif
and endforeach
are alternative syntaxes. Didn't know it either.. BUT :
are missing for the syntax– Fanie Void
Jan 2 at 11:21
@commonsense
endif
and endforeach
are alternative syntaxes. Didn't know it either.. BUT :
are missing for the syntax– Fanie Void
Jan 2 at 11:21
add a comment |
3 Answers
3
active
oldest
votes
/**
* @return array()
*/
public function setAge($users) {
if($users) {
foreach($users as &$user) {
$now = Carbon::now();
$user->age = Carbon::createFromFormat('Y-m-d', $user->birth_date);
$user->age = $now->diffInYears($user->age);
}
}
return $users;
}
/**
* @return array()
*/
public function groupByAge($users) {
$ageGroups = ['less than 20', 'more than 20'];
$ageGroup = ;
foreach ($users as $u) {
switch($u->age) {
case ($u->age < 20) :
$ageGroup['less_then_20'] = 1;
break;
case($u->age >= 20) :
$ageGroup['more_than_20'] = 1;
break;
default:
$ageGroup['error'] = 'error';
break;
}
}
return $ageGroup;
}
public function index() {
$users = DB::table('users')->get;
$users = $this->setAge($users);
$users = $this->groupByAge($users);
print_r("<pre>");
print_r($users);
print_r("</pre>");die();
return view('/users/',['users'=> $users]);
}
you seegroupByAge($users)
this method array variable` $ageGroups ` isn't using in switch case array variable. and in this code too much error solved.
– Shohidur Rahman
Jan 2 at 11:36
Why change+1
as only1
in$ageGroup[A_KEY] =
, the result will only be 1 even if there are more than 1 person in the age category concerned
– Fanie Void
Jan 2 at 12:30
add a comment |
Carbon provides a method to calculate the age directly. So, assuming that $birth_date
already is cast to Carbon instance, it is possible to call age
on that.
I am not sure if you want just count the users in the certain age groups or if you want to group them. As the title indicates to group the users into age groups, you can do the following:
public function index() {
$groupedUsers = User::all()->mapToGroups(function($user, $key) {
if ($user->birth_date->age < 20) {
$ageGroups['less than 20'] = $user
} else {
$ageGroups['more than 20'] = $user
}
return $ageGroups;
});
return view('/users/',[
'users'=> $groupedUsers
]);
}
I think keep using Carbon for the 2 functions is the best answer
– Fanie Void
Jan 2 at 11:35
add a comment |
You should try this:
public function index() {
$users = DB::table('users')->get;
$users = $this->setAge($users);
$users = $this->groupByAge($users);
dd($users); exit();
return view('/users/',[
'users'=> $users]);
}
1
It will not work because the groupByAge function is wrong ...
– Louis R
Jan 2 at 10:42
why would I dd it and then exit()?
– Nick
Jan 2 at 18:26
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%2f54004748%2fgroup-by-age-array-returns-empty%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
/**
* @return array()
*/
public function setAge($users) {
if($users) {
foreach($users as &$user) {
$now = Carbon::now();
$user->age = Carbon::createFromFormat('Y-m-d', $user->birth_date);
$user->age = $now->diffInYears($user->age);
}
}
return $users;
}
/**
* @return array()
*/
public function groupByAge($users) {
$ageGroups = ['less than 20', 'more than 20'];
$ageGroup = ;
foreach ($users as $u) {
switch($u->age) {
case ($u->age < 20) :
$ageGroup['less_then_20'] = 1;
break;
case($u->age >= 20) :
$ageGroup['more_than_20'] = 1;
break;
default:
$ageGroup['error'] = 'error';
break;
}
}
return $ageGroup;
}
public function index() {
$users = DB::table('users')->get;
$users = $this->setAge($users);
$users = $this->groupByAge($users);
print_r("<pre>");
print_r($users);
print_r("</pre>");die();
return view('/users/',['users'=> $users]);
}
you seegroupByAge($users)
this method array variable` $ageGroups ` isn't using in switch case array variable. and in this code too much error solved.
– Shohidur Rahman
Jan 2 at 11:36
Why change+1
as only1
in$ageGroup[A_KEY] =
, the result will only be 1 even if there are more than 1 person in the age category concerned
– Fanie Void
Jan 2 at 12:30
add a comment |
/**
* @return array()
*/
public function setAge($users) {
if($users) {
foreach($users as &$user) {
$now = Carbon::now();
$user->age = Carbon::createFromFormat('Y-m-d', $user->birth_date);
$user->age = $now->diffInYears($user->age);
}
}
return $users;
}
/**
* @return array()
*/
public function groupByAge($users) {
$ageGroups = ['less than 20', 'more than 20'];
$ageGroup = ;
foreach ($users as $u) {
switch($u->age) {
case ($u->age < 20) :
$ageGroup['less_then_20'] = 1;
break;
case($u->age >= 20) :
$ageGroup['more_than_20'] = 1;
break;
default:
$ageGroup['error'] = 'error';
break;
}
}
return $ageGroup;
}
public function index() {
$users = DB::table('users')->get;
$users = $this->setAge($users);
$users = $this->groupByAge($users);
print_r("<pre>");
print_r($users);
print_r("</pre>");die();
return view('/users/',['users'=> $users]);
}
you seegroupByAge($users)
this method array variable` $ageGroups ` isn't using in switch case array variable. and in this code too much error solved.
– Shohidur Rahman
Jan 2 at 11:36
Why change+1
as only1
in$ageGroup[A_KEY] =
, the result will only be 1 even if there are more than 1 person in the age category concerned
– Fanie Void
Jan 2 at 12:30
add a comment |
/**
* @return array()
*/
public function setAge($users) {
if($users) {
foreach($users as &$user) {
$now = Carbon::now();
$user->age = Carbon::createFromFormat('Y-m-d', $user->birth_date);
$user->age = $now->diffInYears($user->age);
}
}
return $users;
}
/**
* @return array()
*/
public function groupByAge($users) {
$ageGroups = ['less than 20', 'more than 20'];
$ageGroup = ;
foreach ($users as $u) {
switch($u->age) {
case ($u->age < 20) :
$ageGroup['less_then_20'] = 1;
break;
case($u->age >= 20) :
$ageGroup['more_than_20'] = 1;
break;
default:
$ageGroup['error'] = 'error';
break;
}
}
return $ageGroup;
}
public function index() {
$users = DB::table('users')->get;
$users = $this->setAge($users);
$users = $this->groupByAge($users);
print_r("<pre>");
print_r($users);
print_r("</pre>");die();
return view('/users/',['users'=> $users]);
}
/**
* @return array()
*/
public function setAge($users) {
if($users) {
foreach($users as &$user) {
$now = Carbon::now();
$user->age = Carbon::createFromFormat('Y-m-d', $user->birth_date);
$user->age = $now->diffInYears($user->age);
}
}
return $users;
}
/**
* @return array()
*/
public function groupByAge($users) {
$ageGroups = ['less than 20', 'more than 20'];
$ageGroup = ;
foreach ($users as $u) {
switch($u->age) {
case ($u->age < 20) :
$ageGroup['less_then_20'] = 1;
break;
case($u->age >= 20) :
$ageGroup['more_than_20'] = 1;
break;
default:
$ageGroup['error'] = 'error';
break;
}
}
return $ageGroup;
}
public function index() {
$users = DB::table('users')->get;
$users = $this->setAge($users);
$users = $this->groupByAge($users);
print_r("<pre>");
print_r($users);
print_r("</pre>");die();
return view('/users/',['users'=> $users]);
}
answered Jan 2 at 11:02
Shohidur RahmanShohidur Rahman
314
314
you seegroupByAge($users)
this method array variable` $ageGroups ` isn't using in switch case array variable. and in this code too much error solved.
– Shohidur Rahman
Jan 2 at 11:36
Why change+1
as only1
in$ageGroup[A_KEY] =
, the result will only be 1 even if there are more than 1 person in the age category concerned
– Fanie Void
Jan 2 at 12:30
add a comment |
you seegroupByAge($users)
this method array variable` $ageGroups ` isn't using in switch case array variable. and in this code too much error solved.
– Shohidur Rahman
Jan 2 at 11:36
Why change+1
as only1
in$ageGroup[A_KEY] =
, the result will only be 1 even if there are more than 1 person in the age category concerned
– Fanie Void
Jan 2 at 12:30
you see
groupByAge($users)
this method array variable` $ageGroups ` isn't using in switch case array variable. and in this code too much error solved.– Shohidur Rahman
Jan 2 at 11:36
you see
groupByAge($users)
this method array variable` $ageGroups ` isn't using in switch case array variable. and in this code too much error solved.– Shohidur Rahman
Jan 2 at 11:36
Why change
+1
as only 1
in $ageGroup[A_KEY] =
, the result will only be 1 even if there are more than 1 person in the age category concerned– Fanie Void
Jan 2 at 12:30
Why change
+1
as only 1
in $ageGroup[A_KEY] =
, the result will only be 1 even if there are more than 1 person in the age category concerned– Fanie Void
Jan 2 at 12:30
add a comment |
Carbon provides a method to calculate the age directly. So, assuming that $birth_date
already is cast to Carbon instance, it is possible to call age
on that.
I am not sure if you want just count the users in the certain age groups or if you want to group them. As the title indicates to group the users into age groups, you can do the following:
public function index() {
$groupedUsers = User::all()->mapToGroups(function($user, $key) {
if ($user->birth_date->age < 20) {
$ageGroups['less than 20'] = $user
} else {
$ageGroups['more than 20'] = $user
}
return $ageGroups;
});
return view('/users/',[
'users'=> $groupedUsers
]);
}
I think keep using Carbon for the 2 functions is the best answer
– Fanie Void
Jan 2 at 11:35
add a comment |
Carbon provides a method to calculate the age directly. So, assuming that $birth_date
already is cast to Carbon instance, it is possible to call age
on that.
I am not sure if you want just count the users in the certain age groups or if you want to group them. As the title indicates to group the users into age groups, you can do the following:
public function index() {
$groupedUsers = User::all()->mapToGroups(function($user, $key) {
if ($user->birth_date->age < 20) {
$ageGroups['less than 20'] = $user
} else {
$ageGroups['more than 20'] = $user
}
return $ageGroups;
});
return view('/users/',[
'users'=> $groupedUsers
]);
}
I think keep using Carbon for the 2 functions is the best answer
– Fanie Void
Jan 2 at 11:35
add a comment |
Carbon provides a method to calculate the age directly. So, assuming that $birth_date
already is cast to Carbon instance, it is possible to call age
on that.
I am not sure if you want just count the users in the certain age groups or if you want to group them. As the title indicates to group the users into age groups, you can do the following:
public function index() {
$groupedUsers = User::all()->mapToGroups(function($user, $key) {
if ($user->birth_date->age < 20) {
$ageGroups['less than 20'] = $user
} else {
$ageGroups['more than 20'] = $user
}
return $ageGroups;
});
return view('/users/',[
'users'=> $groupedUsers
]);
}
Carbon provides a method to calculate the age directly. So, assuming that $birth_date
already is cast to Carbon instance, it is possible to call age
on that.
I am not sure if you want just count the users in the certain age groups or if you want to group them. As the title indicates to group the users into age groups, you can do the following:
public function index() {
$groupedUsers = User::all()->mapToGroups(function($user, $key) {
if ($user->birth_date->age < 20) {
$ageGroups['less than 20'] = $user
} else {
$ageGroups['more than 20'] = $user
}
return $ageGroups;
});
return view('/users/',[
'users'=> $groupedUsers
]);
}
edited Jan 2 at 11:34
answered Jan 2 at 11:22
common sensecommon sense
2,57351625
2,57351625
I think keep using Carbon for the 2 functions is the best answer
– Fanie Void
Jan 2 at 11:35
add a comment |
I think keep using Carbon for the 2 functions is the best answer
– Fanie Void
Jan 2 at 11:35
I think keep using Carbon for the 2 functions is the best answer
– Fanie Void
Jan 2 at 11:35
I think keep using Carbon for the 2 functions is the best answer
– Fanie Void
Jan 2 at 11:35
add a comment |
You should try this:
public function index() {
$users = DB::table('users')->get;
$users = $this->setAge($users);
$users = $this->groupByAge($users);
dd($users); exit();
return view('/users/',[
'users'=> $users]);
}
1
It will not work because the groupByAge function is wrong ...
– Louis R
Jan 2 at 10:42
why would I dd it and then exit()?
– Nick
Jan 2 at 18:26
add a comment |
You should try this:
public function index() {
$users = DB::table('users')->get;
$users = $this->setAge($users);
$users = $this->groupByAge($users);
dd($users); exit();
return view('/users/',[
'users'=> $users]);
}
1
It will not work because the groupByAge function is wrong ...
– Louis R
Jan 2 at 10:42
why would I dd it and then exit()?
– Nick
Jan 2 at 18:26
add a comment |
You should try this:
public function index() {
$users = DB::table('users')->get;
$users = $this->setAge($users);
$users = $this->groupByAge($users);
dd($users); exit();
return view('/users/',[
'users'=> $users]);
}
You should try this:
public function index() {
$users = DB::table('users')->get;
$users = $this->setAge($users);
$users = $this->groupByAge($users);
dd($users); exit();
return view('/users/',[
'users'=> $users]);
}
answered Jan 2 at 10:39
user10186369
1
It will not work because the groupByAge function is wrong ...
– Louis R
Jan 2 at 10:42
why would I dd it and then exit()?
– Nick
Jan 2 at 18:26
add a comment |
1
It will not work because the groupByAge function is wrong ...
– Louis R
Jan 2 at 10:42
why would I dd it and then exit()?
– Nick
Jan 2 at 18:26
1
1
It will not work because the groupByAge function is wrong ...
– Louis R
Jan 2 at 10:42
It will not work because the groupByAge function is wrong ...
– Louis R
Jan 2 at 10:42
why would I dd it and then exit()?
– Nick
Jan 2 at 18:26
why would I dd it and then exit()?
– Nick
Jan 2 at 18:26
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.
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%2f54004748%2fgroup-by-age-array-returns-empty%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
2
$groupByAge
is not the variable you want to dd. instead dd$users
variable– Rahul Meshram
Jan 2 at 10:38
What if
$u->age == 20
?– kerbholz
Jan 2 at 10:46
1
What does
endforeach
andendif
mean in PHP context? What is$u
? You using itu->birth_date
(btw. missing a $ sign) without declaring it before. Please provide a code example without syntax errors.– common sense
Jan 2 at 10:49
Check your
groupByAge
function, it returns$age
which is never set. And thatforeach
isn't closed anywhere? Also,$ageGroup['less then 20']
is not the same as$ageGroup['less than 20']
.– kerbholz
Jan 2 at 10:54
@commonsense
endif
andendforeach
are alternative syntaxes. Didn't know it either.. BUT:
are missing for the syntax– Fanie Void
Jan 2 at 11:21