Giter Site home page Giter Site logo

math_eval's Introduction

✖️➕➖➗ Math Eval Helper Function

Build Status Coverage Status StyleCI Packagist

This PHP package provides a math_eval helper function, that allows safe evaluation of mathematical expressions, without the use of the potentially dangerous eval function.

Installation

The math_eval package can be easily installed using Composer. Just run the following command from the root of your project.

composer require "langleyfoxall/math_eval"

If you have never used the Composer dependency manager before, head to the Composer website for more information on how to get started.

Usage

To evaluate a basic mathematical expression, just pass its string representation to the math_eval function.

Here are some basic usage examples:

$two = math_eval('1 + 1');
$three = math_eval('5 - 2');
$ten = math_eval('2 * 5');
$four = math_eval('8 / 2');

It is also possible to pass expression variables. See the examples below.

$ten = math_eval('a + b', ['a' => 7, 'b' => 3]);
$fifteen = math_eval('x * y', ['x' => 3, 'y' => 5]);

Credit

This package makes use of the mossadal/math-parser package.

math_eval's People

Contributors

divineomega avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.