Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
The code was working perfectly until when I installed
XAMPP 8 (PHP 8)
.
if(isset($_POST["submit"])){
@$subject = $_POST['subject'];
@$term = $_POST['term'];
@$session = $_POST['session'];
@$size = count($_POST['adm_num']);
@$size = count($_POST['ca1']);
@$size = count($_POST['ca2']);
@$size = count($_POST['ca3']);
$i = 0;
while ($i < $size) {
$ca1= $_POST['ca1'][$i];
$ca2= $_POST['ca2'][$i];
$ca3= $_POST['ca3'][$i];
$adm_num = $_POST['adm_num'][$i];
–
@$term = $_POST['term'];
@$session = $_POST['session'];
@$size = count((array)$_POST['adm_num']));
@$size = count((array)$_POST['ca1']));
@$size = count((array)$_POST['ca2']));
@$size = count((array)$_POST['ca3']));
$i = 0;
while ($i < $size) {
$ca1= $_POST['ca1'][$i];
$ca2= $_POST['ca2'][$i];
$ca3= $_POST['ca3'][$i];
$adm_num = $_POST['adm_num'][$i];
–
For easier code update for PHP8 I made my own function
function count_($array) {
return is_array($array) ? count($array) : 0;
and then I mass replaced count($value) with count_($value)
Quoting from the official php docs for count():
Counts all elements in an array, or something in an object.
The error you're getting is pretty obvious. One of these four variables($_POST['adm_num'], $_POST['ca1'], $_POST['ca2'], $_POST['ca3']) is not an array or maybe more.
You can find out about the type of a variable using gettype(). It'll tell you that which variable does not contains an array. You can than change it to array.
P.s: You're overriding your $size variable three times. Why is that?
In the doc it say :
Return Values
Returns the number of elements in value. When the parameter is neither an array nor an object with implemented Countable interface, 1 will be returned. There is one exception, if value is null, 0 will be returned.
It look like it a bug ?!?
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.