Req #77918 [Csd->Nab]: i need a feature through array.

From: Date: Thu, 18 Apr 2019 15:59:38 +0000
Subject: Req #77918 [Csd->Nab]: i need a feature through array.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220522@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77918&edit=1 ID: 77918 Updated by: requinix@php.net Reported by: anjvelu at gmail dot com Summary: i need a feature through array. -Status: Closed +Status: Not a bug Type: Feature/Change Request Package: Unknown/Other Function PHP Version: Next Major Version Assigned To: girgias Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2019-04-18 13:08:21] sjon at hortensius dot net what's wrong with doing this yourself? function getComments(){ $comments = [ "id" => 1, "comment" => "this is test comment", "favorite_users" => [10, 15, 2, 5], ]; return $comments + ['favorite_users_count' => count($comments['favorite_users'])]; } See https://3v4l.org/Xmv2Y ------------------------------------------------------------------------ [2019-04-18 13:07:46] girgias@php.net Just have a variable which holds `array(10, 15, 2, 5)` and you can reference this variable in the count function. ------------------------------------------------------------------------ [2019-04-18 12:56:37] anjvelu at gmail dot com Description: ------------ i need a feature through array. Test script: --------------- function getComments(){ return array( "id" => 1, "comment" => "this is test comment", "favorite_users" => array(10, 15, 2, 5), "favorite_users_count" => count(array(10, 15, 2, 5)) ); } Expected result: ---------------- --- From manual page: https://php.net/language.types.array --- i need a feature through array. function getComments(){ return array( "id" => 1, "comment" => "this is test comment", "favorite_users" => array(10, 15, 2, 5), "favorite_users_count" => count(array(10, 15, 2, 5)) ); } The above function, there is key "favorite_users" having values and the key "favorite_users_count" only holds count of array key "favorite_users". Here the key "favorite_users_count" again setting the values for count array. Is there any way to achieve the count calling the array key "favorite_users". Thanks ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77918&edit=1

« previous php.bugs (#220522) next »