PHP code example of fangzesheng / algorithm

1. Go to this page and download the library: Download fangzesheng/algorithm library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fangzesheng / algorithm example snippets


try {
    // twoNumberSum为算法题目,[[1,3,4,56,34,5,2,6],8]为该算法所需要参数,该算法求两个数和所需两个参数,分别为[1,3,4,56,34,5,2,6]和8
    $upload = new Algorithm('twoNumberSum',[[1,3,4,56,34,5,2,6],8]);
    //achieve 算法实现函数
    print_r($upload->achieve());
    //thinking 算法思路函数
    print_r($upload->thinking());
} catch (Exception $e) {
    // 出错啦,处理下吧
    echo $e->getMessage() . PHP_EOL;
}