can anyone help me convert this to c++??

function show_me($info) {
$arr = array('fruit' => 'apple', 'car' => 'bmw');
return $arr[$info];

echo show_me('fruit');
//or echo show_me('car')

Edited by happygeek: fixed formatting

10 Years
Discussion Span
Last Post by som3on3

ok, now how can i put all that array in a new array?
so that i can have more then 1 array["fruit"] = "apple";
to be array["fruit"] = apple;
array["fruit"] = strawberry;
array["car"] = bmw;
array["car"] = audi;

please help :(


really thanks for your big help, can i vote you somewhere or something like this?

Votes + Comments
You click on "Add to reputation" at the top of each post

sorry for disturbing;
i have another question

i want to make a function len()

so can return the size of a vector
how can i make

int len( vector< any_type_of_vector(int,string....) array) {
   return (int)array.size();

thanks for your time


Why would you want to make a function for that, when the size() function already exists?
Here's a code example of size() using Salem's demo-code:

std::map <std::string, std::vector<std::string> > array;
        array["fruit"].push_back( "apple" );
        array["fruit"].push_back( "pear" );

        cout << "The map 'array' has " << array.size() << " vector(s)\n";
        cout << "The vector 'fruit' in map 'array' has " 
               << array["fruit"].size() << " elements\n";

thanks for the help, found in the end something;
well i need a function like that because i am using multiple types if arrays including array[] so to type everytime sizeof(array)/sizeof(int) takes more time then i desire, and know my code reached 2000 lines, and is not even done yet, hard to write every type of array.size()
so i made this:

template <typename T>
int len(vector< T > array) {
	return (int)array.size();

int len(int *array) {
	int size = sizeof(array)/sizeof(int);
	return size;

wich helps me a lot for doing:

for(int i=0; i<len(array); i++) {


nice, isn't it?
tanks once again

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.