dongshi1934 2016-12-06 15:18
浏览 57

来自静态属性的内爆数组?

I have a class with two static properties.

$statuses is an array with the status id and their string values for display.

$status_changes is an array of the current status id and the value is an array of allowed status changes.

class Status {
    public static $statuses = [
        1 => 'Box Stock',
        11 => 'Box Stock (Refurbished)',
        2 => 'Transit',
        3 => 'Active',
        4 => 'Inactive',
        12 => 'RMA Authorized',
        5 => 'RMA',
        6 => 'Scrap',
        8 => 'Customer Spare',
        9 => 'Consigned',
        13 => 'Holding',
        10 => 'Internal Use',
        7 => 'Unknown'
    ];

    public static $status_changes = [
        1 => [2, 3, 10, 13],
        11 => [2, 10, 13],
        2 => [3, 10, 12, 13],
        3 => [4],
        4 => [3, 6, 7, 11, 12],
        12 => [5, 6, 11],
        5 => [6, 11],
        6 => [7],
        8 => [3],
        9 => [3, 8],
        13 => [3, 8],
        10 => [3, 6, 11],
        7 => [6, 11]
    ];

    function echoAllowed($status) {
        echo implode(', ', array_map(function ($s) { 
            return Status::$statuses[$s]; 
        },
        self::$status_changes[$status]));
    }
}

$s = new Status();
$s->echoAllowed(1);
// Should print "Transit, Active, Internal Use, Holding".

What is the best way to implode the list of allowed status changes, given a status id? (As I've done in the echoAllowed() method.)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本