Huseyin Yilmaz
Huseyin Yilmaz

Reputation: 13

Php Static Class and Normal Class

$export = db::get($data);

foreach ($export as $user) {
    //
}

echo "Totol User: " . $export->count();

Hello, I have a problem. I'm pulling array() with db::get($data). Then I want to show the total number of records with a function such as $export->count().

Is there an example suitable for this structure? Can you help me?

Upvotes: 0

Views: 51

Answers (3)

Don't Panic
Don't Panic

Reputation: 41810

There's not much to it, but there seems to be a misunderstanding about what an array can do.

An array in PHP is not an object with methods like ->count(). It has no methods or properties.

Instead you pass the array as an argument to the built-in PHP function count().

echo "Totol User: " . count($export);

The sizeof() function is an alias of count(). They are interchangeable.

Upvotes: 2

Mexidense
Mexidense

Reputation: 1171

I don't know what is db::get($data) function but if it's return an array, you can count number of items with sizeof function:

sizeof($export);

Source: http://php.net/manual/en/function.sizeof.php

Upvotes: 0

Peter Szalay
Peter Szalay

Reputation: 386

You can also use sizeof():

echo "Total number of users: " . sizeof($export);

Check out w3schools.com fro more info: https://www.w3schools.com/php/func_array_sizeof.asp

Also if db is a variable, the it should be $db not simply db

Upvotes: 0

Related Questions