kodie Posted October 19, 2009 Share Posted October 19, 2009 ok so i have a string that looks like this: blog:edit_all,delete_all|users:edit_all,delete_all|settings and i want to make a code that can take that string and put it in a multi-layered array like this: Array ( [0] => blog ( [0] => edit_all [1] => delete_all ) [1] => users ( [0] => edit_all [1] => delete_all ) [2] => settings ) i've googled and everything and cant seem to get anything to work. ive come close but not quite. any ideas? thank you. Link to comment https://forums.phpfreaks.com/topic/178183-solved-generate-multilayered-array-from-string/ Share on other sites More sharing options...
trq Posted October 19, 2009 Share Posted October 19, 2009 ive come close but not quite. Lets see your code then. Link to comment https://forums.phpfreaks.com/topic/178183-solved-generate-multilayered-array-from-string/#findComment-939479 Share on other sites More sharing options...
kodie Posted October 19, 2009 Author Share Posted October 19, 2009 here it is: $permissions1 = split("\|", $_SESSION['permissions']); $i = "0"; foreach ($permissions1 as &$perm) { $permissions2 = split(":", $perm); $permissions_a[$i] = $permissions2[0]; $permissions_a[$i] = split(",", $permissions2[1]); $i++; } and it outputs the array like this: Array ( [0] => Array ( [0] => edit_all [1] => delete_all ) [1] => Array ( [0] => edit_all [1] => delete_all ) [2] => Array ( [0] => ) ) Link to comment https://forums.phpfreaks.com/topic/178183-solved-generate-multilayered-array-from-string/#findComment-939481 Share on other sites More sharing options...
kodie Posted October 19, 2009 Author Share Posted October 19, 2009 welp i ended up fixing her myself. Here's the code that worked just incase anyone wanted to know: $permissions1 = split("\|", $_SESSION['permissions']); foreach ($permissions1 as &$perm) { $permissions2 = split(":", $perm); if (isset($permissions2[1])) { $permissions[$permissions2[0]] = split(",", $permissions2[1]); } else { $permissions[$permissions2[0]] = Array("null"); } } which gives me this array: Array ( [blog] => Array ( [0] => edit_all [1] => delete_all ) [users] => Array ( [0] => edit_all [1] => delete_all ) [settings] => Array ( [0] => null ) ) thanks anyways. EDIT: if anyone cantell me how to mark as solved i will do that as well. Link to comment https://forums.phpfreaks.com/topic/178183-solved-generate-multilayered-array-from-string/#findComment-939499 Share on other sites More sharing options...
anatak Posted October 19, 2009 Share Posted October 19, 2009 at the bottom of the last post is a button with topic solved click that one and your topic will be marked solved Link to comment https://forums.phpfreaks.com/topic/178183-solved-generate-multilayered-array-from-string/#findComment-939502 Share on other sites More sharing options...
kodie Posted October 20, 2009 Author Share Posted October 20, 2009 ah, i see it now. thanks. Link to comment https://forums.phpfreaks.com/topic/178183-solved-generate-multilayered-array-from-string/#findComment-940177 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.