0

i used kirki drag and drop wordpress plugin for my site to create a sortable list when dragable is enabled.

i was able to create a setting that outputs this array, when i did var_dump for the settings here was what i got

array(3) { [0]=> string(10) "Big Grid 1" [1]=> string(10) "Big Grid 2" [2]=> string(10) "Big Grid 3" }

when in var_dump it sorts correctly when i drag and drop any element, they take there place as sorted in the var_dump array, to me the array given is completely useless till i set values for them .

so the question is how do i output them in php to get sorted just as they where in the array.

i tried switch case but its not working.

here is my code

foreach ($array[0] as $key => $value) {
switch ($key) {
    case 'Big grid 1' :
        // do something
        break ;
    case 'Big grid 2' :
        // do something
        break ;
    case 'Big grid 3' :
        // do something
        break ;
 }
 }

please i need help on this one.

hope my question was clear.

i am no PHP expert, thus a complex answer would be well appreciated.

2
  • 3
    that are values, not keys Commented Jan 7, 2018 at 13:51
  • 1
    switch ($value) in your case not switch ($key) ! Commented Jan 7, 2018 at 13:54

1 Answer 1

2

not sure what you are trying to do with using switch statement and I'm not really sure what you are trying to accomplish with that code you have,

but as I understand about your question, you just want to output the value of an array,

then you can do something like

$items = array("Big Grid 1","Big Grid 2","Big Grid 3");

$output = '';
foreach ($items as $item ) {
    $output .= $item .'<br/>';
}

echo $output; // or return $output if you need a return value
Sign up to request clarification or add additional context in comments.

5 Comments

i want to output the value of the array as indexed in the array , like in order, the sortable does the order .
foreach handles that for you
or post your desired expected output to make it more clear of what you need
the default value from the array has , array(1) { [0]=> string(10) "Big Grid 1" } , when i check visibility mode on in other sortable item they become visible , and the array changes to array(3) { [0]=> string(10) "Big Grid 1" [1]=> string(10) "Big Grid 2" [2]=> string(10) "Big Grid 3" } , if i drag and drop any item, they re-order in the array say array item two takes the place of array item one when i drag and drop, i just want a way to make the value maintain they index in the array (obviously when sorted ) . this is how best i can explain my problem. - snag.gy/chxVb3.jpg
ey , it worked m thanks bro i jess figured it out ... infact i didnt figure it out, i used it like dat ... tanks a million tyms

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.