• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 362
  • Last Modified:

feet and inches to inches

turn this feet-inches to inches conversion
$inches = current(explode("'", $height)) * 12 + end(explode("'", rtrim(trim($height), '"')));


an object oriented method (not just a procedural function) that accepts feet-inches as a parameter and returns inches
  • 2
1 Solution
Mark BradyPrincipal Data EngineerCommented:
I think you have already asked this in another question however if you want this done in an object class you just pout it inside a function. Here's a quick example.


// instantiate the class object
$convert = new Conversion();

// call its run method (function)
$length = "6'3''"; // 6 foot 3 inches

$inches = $convert->feet_to_inches($length);


// the end.....

class Conversion {
    public function feet_to_inches($length) {
        // explode the string
        $temp = array_map('trim', explode("'", $length));
        return ($temp[0] * 12) + $temp[1];


Open in new window

rgb192Author Commented:
that addition temp[0] (feet) + temp[1] inches makes code easy to understand

Mark BradyPrincipal Data EngineerCommented:
You're welcome
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now