Martin
Martin

Reputation: 375

getting N number in a number

I have an array and I am getting its length using sizeof(). In the size of the array I want to get how many 10 there are in that number. I used % in getting my number like:

$arraysize = 13;//sizeof($array)
$numberoften = $arraysize % 10 // getting 3

From here I know that I am wrong. What i want to get is 2. Because I want to get every 10. Like if length is 9 I want to get 1. If length is 31 I want to get 4.

What is the correct function of way to get my desired output?

Upvotes: 1

Views: 46

Answers (2)

Osama
Osama

Reputation: 3040

Use ceil() function

 $arraysize = 13;//sizeof($array);
$numberoften =ceil( $arraysize/10);

Or

Use round() function

$arraysize = 13;//sizeof($array);
$numberoften =round( $arraysize/10);

Upvotes: 0

Phil
Phil

Reputation: 164794

What you're after is ceil()

Returns the next highest integer value by rounding up value if necessary.

$numberoften = ceil($arraysize / 10);

There's also floor() if you want to round the number down to the nearest integer. This would seem to fit better with your question...

I want to get how many 10 there are in that number

Upvotes: 1

Related Questions