Solved

feet and inches to inches

Posted on 2013-11-24
3
352 Views
Last Modified: 2013-11-25
turn this feet-inches to inches conversion
$inches = current(explode("'", $height)) * 12 + end(explode("'", rtrim(trim($height), '"')));

to

an object oriented method (not just a procedural function) that accepts feet-inches as a parameter and returns inches
0
Comment
Question by:rgb192
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
Mark Brady earned 500 total points
ID: 39673581
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.

<?php

// 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);

var_dump($inches);


// 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

0
 

Author Closing Comment

by:rgb192
ID: 39673588
that addition temp[0] (feet) + temp[1] inches makes code easy to understand

thanks
0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 39675417
You're welcome
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question