PHP Questions Home
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

I am not interested in the values in the arrays, how can I discard them?


One simple way to do this, if you just want the information about the keys, is to use the array_keys function to create an array of the keys. It does what it says on the tin, but here's a quick example:

<?php

$values 
= array(10=>"I","Don't","Care","About","Values");
print_r($values);

$whatvalues array_keys($values);
print_r($whatvalues);
?>


Here is the resultant output from this:

Array
(
[10] => I
[11] => Don't
[12] => Care
[13] => About
[14] => Values
)
Array
(
[0] => 10
[1] => 11
[2] => 12
[3] => 13
[4] => 14
)

We can see that the values have been discarded and we now have an array containing the keys as the values.



ASK A QUESTION

More arrays PHP Questions

what is the return value of array_unique()?

How do I reverse sort an array by key?

how sorting an array with keys?

How do I check if a variable is of array type?

How do I change: function wordlimit($string, $length = 50, $ellipsis = "...") { $words = explode(' ', strip_tags($string)); if (count($words) > $length) return implode(' ', array_slice($words, 0, $length)) . $ellipsis; else



Custom Search