News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

problem with output in foreach of an Array

Started by Pipke, January 02, 2015, 08:14:29 AM

Previous topic - Next topic

Pipke


Array ( [0] => activate [1] => Register.php [2] => Activate [3] => admin [4] => Admin.php [5] => AdminMain [6] => announce [7] => Post.php [8] => AnnounceTopic [9] => attachapprove [10] => ManageAttachments.php [11] => ApproveAttach [12] => buddy [13] => Subs-Members.php [14] => BuddyListToggle [15] => calendar [16] => Calendar.php [17] => CalendarMain [18] => clock [19] => Calendar.php [20] => clock [21] => collapse [22] => BoardIndex.php [23] => CollapseCategory


want to output in the foreach

to get the different value strings of

[0] and [2]
then [3] and [5]
then [6] and [8]
etc etc.

so it will output:

$string_first, [0] -> activate
$string_first, [3] -> admin
etc

and

$string_second, [2]  -> Activate
$string_second, [5]  -> Admin
etc


thx for the help.

"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Arantor

Um, where are you getting this array from? Surely you'd build the array better in the first place?

Pipke

Quote from: Arantor on January 02, 2015, 08:26:02 AM
Um, where are you getting this array from? Surely you'd build the array better in the first place?

with this

// Get file contents of the monstrous $_REQUEST['action'] array - $_REQUEST['action'] => array($file, $function).
    $rft_file_index = file_get_contents($boarddir . '/index.php');
    $rft_file_index2 = strstr($rft_file_index, '$actionArray = array(');
    $rft_file_index3 = substr($rft_file_index2, 0, strpos( $rft_file_index2, '// Allow modifying $actionArray easily.'));

$replace = array(
'$actionArray' => '',
'array' => '',
);
$output = str_replace_assoc($replace,$rft_file_index3);

$keywords = preg_split("/[=\s,';(>)]+/", $output);

$keywords1 = array_filter(array_slice($keywords,1));



but to the topic,  who can help me out,  tryed with array slice an a counter stil no luck for finding what i want to get this working.
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Arantor

Doing this via file grabbing is a bad idea because hooked actions won't be found at all (and more and more mods are using this) and you would be much better adding something to the integrate_actions hook which will give you the array in almost exactly the format you want.

Pipke

Quote from: Arantor on January 02, 2015, 08:43:51 AM
Doing this via file grabbing is a bad idea because hooked actions won't be found at all (and more and more mods are using this) and you would be much better adding something to the integrate_actions hook which will give you the array in almost exactly the format you want.

i already use that with this  ;D


// Get $actionArray hook easily.
    call_integration_hook('integrate_actions', array(&$actionArray));
    $rft_searchterm =  '\''. $context['current_action'] .'\'';

// Check if the action page exists
    if ((stripos($rft_file_index3, $rft_searchterm) !== false) || (array_key_exists($context['current_action'], $actionArray)))



but i cant find any 'hardcoded (array for all the action pages)' in the database? That why i want to grab it from the index.php file. Its the only solution i can think of the get it. This way if user use mods who have edited the index.php to add costum action pages it will work with mine(mod).
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Arantor

Quotebut i cant find any 'hardcoded (array for all the action pages)' in the database?

There isn't one.

QuoteThis way if user use mods who have edited the index.php to add costum action pages it will work with mine(mod).

Except there are more and more mods that DON'T edit index.php.

Quotei already use that with this

No, you're not.

If you attach a function to the hook (you know, by using the hook properly), you will find that $actionArray gets handed to your function ready-made.

Though even that isn't fool proof, I can think of cases where even that wouldn't work properly.

Pipke

Well sofar it works if i call // Get $actionArray hook easily.
btw it can also be grabbed with a db function.

to topic agian, i need help with that output array in first post any suggestions are welcome.
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Arantor

My suggestion continues to be: Don't do what you're trying to do, and do it the best way possible - get it provided in a ready to go format, whilst getting more of the values than you could possibly get the way you're trying to do it.

Advertisement: