0

this question is for ask if there is any better way to create an array with values like that

array(
    [0] => 'course_25_expires',
    [1] => 'course_31_expires',
    [2] => 'course_43_expires',
    [3] => 'course_45_expires',
    [4] => 'course_48_expires',
    [5] => 'course_67_expires'
)

by just using another array that can have only the IDs for that records as the one that following:

array(
    [0] => 25,
    [1] => 31,
    [2] => 43,
    [3] => 45,
    [4] => 48,
    [5] => 67
)

is there any kind of walker in PHP that can use a kind of "string template" and an array with values and produce an array with mix of the values and the template ?

1 Answer 1

1

You can use array_map() and an anonymous function to do this:

$output = array_map(
    function ($item) { return "course_{$item}_expires"; },
    $data
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.