Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8339099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:47:24+00:00 2026-06-09T04:47:24+00:00

i’m writing a php extension for my c++ library which is defined something like

  • 0

i’m writing a php extension for my c++ library which is defined something like this:

bool getPids(map<string,string> pidsMap, vector<string> ids);

now, i’m writing a php wrapper for above function like this.

ZEND_METHOD(myFInfo, get_pids)
{
    zval *idsArray;

    if (zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "a",
                                &idsArray ) == FAILURE )
    {
        RETURN_NULL();
    }
}

now i want to call getPids(), but i don’t know the proper way to pass idsArray as vector into the c++ function.

after some search on web, i found an example where zval array is iterated to read each values, and i thought maybe i can use this to create a vector.

PHP_FUNCTION(hello_array_strings)
{
    zval *arr, **data;
    HashTable *arr_hash;
    HashPosition pointer;
    int array_count;
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &arr) == FAILURE) {
        RETURN_NULL();
    }

arr_hash = Z_ARRVAL_P(arr);
array_count = zend_hash_num_elements(arr_hash);

php_printf("The array passed contains %d elements", array_count);

for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); zend_hash_get_current_data_ex(arr_hash, (void**) &data, &pointer) == SUCCESS; 

zend_hash_move_forward_ex(arr_hash, &pointer)) {

            if (Z_TYPE_PP(data) == IS_STRING) {
                PHPWRITE(Z_STRVAL_PP(data), Z_STRLEN_PP(data));
                php_printf("
    ");
            }
        }
        RETURN_TRUE;
    }

but is this the best approach? or is there a better way to do this?

thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:47:26+00:00Added an answer on June 9, 2026 at 4:47 am

    To populate a std::vector<std::string> from a PHP array, here’s how I’d do it (the short version):

    std::vector<std::string> vec;
    HashTable *arr_hash = Z_ARRVAL_P(arr);
    zval **arr_value;
    for(zend_hash_internal_pointer_reset(arr_hash);
        zend_hash_get_current_data(arr_hash, (void **)&arr_value) == SUCCESS;
        zend_hash_move_forward(arr_hash))
    {
        vec.push_back(Z_STRVAL_PP(arr_value));
    }
    

    …where arr is your input zval *, and vec is your output vector.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.